|
13 | 13 | from py import std
|
14 | 14 |
|
15 | 15 |
|
| 16 | +XPROCESS_BLOCK_DELIMITER = "@@__xproc_block_delimiter__@@" |
| 17 | + |
| 18 | + |
16 | 19 | class XProcessInfo:
|
17 | 20 | """Holds information of an active process instance represented by
|
18 | 21 | a XProcess Object and offers recursive termination functionality of
|
@@ -81,7 +84,7 @@ def terminate(self, *, kill_proc_tree=True, timeout=20):
|
81 | 84 | self._signal_process(p, signal.SIGTERM)
|
82 | 85 | _, alive = psutil.wait_procs(kill_list, timeout=timeout)
|
83 | 86 |
|
84 |
| - # forcefuly terminate procs still running |
| 87 | + # forcefully terminate procs still running |
85 | 88 | for p in alive:
|
86 | 89 | self._signal_process(p, signal.SIGKILL)
|
87 | 90 | _, alive = psutil.wait_procs(kill_list, timeout=timeout)
|
@@ -229,7 +232,8 @@ def ensure(self, name, preparefunc, restart=False):
|
229 | 232 | starter = preparefunc(controldir, self)
|
230 | 233 | args = [str(x) for x in starter.args]
|
231 | 234 | self.log.debug("%s$ %s", controldir, " ".join(args))
|
232 |
| - stdout = open(str(info.logpath), "wb", 0) |
| 235 | + stdout = open(str(info.logpath), "a+b", 0) |
| 236 | + stdout.write(bytes(f"{XPROCESS_BLOCK_DELIMITER}\n", "utf8")) |
233 | 237 |
|
234 | 238 | # is env still necessary? we could pass all in popen_kwargs
|
235 | 239 | kwargs = {"env": starter.env}
|
@@ -266,6 +270,18 @@ def ensure(self, name, preparefunc, restart=False):
|
266 | 270 | # cleanup later during teardown phase
|
267 | 271 | xresource.fhandle = info.logpath.open()
|
268 | 272 |
|
| 273 | + # skip previous process logs |
| 274 | + lines = info.logpath.open().readlines() |
| 275 | + if lines: |
| 276 | + proc_block_counter = sum( |
| 277 | + 1 for line in lines if XPROCESS_BLOCK_DELIMITER in line |
| 278 | + ) |
| 279 | + for line in xresource.fhandle: |
| 280 | + if XPROCESS_BLOCK_DELIMITER in line: |
| 281 | + proc_block_counter -= 1 |
| 282 | + if proc_block_counter <= 0: |
| 283 | + break |
| 284 | + |
269 | 285 | self.resources.append(xresource)
|
270 | 286 |
|
271 | 287 | if not restart:
|
|
0 commit comments