cmd: wait on status after killing process
This commit is contained in:
@@ -198,21 +198,33 @@ def terminate_process_group(process: subprocess.Popen) -> Iterator[None]:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def _terminate_process(process: subprocess.Popen) -> None:
|
||||||
|
try:
|
||||||
|
process.terminate()
|
||||||
|
except ProcessLookupError:
|
||||||
|
return
|
||||||
|
|
||||||
|
with contextlib.suppress(subprocess.TimeoutExpired):
|
||||||
|
# give the process time to terminate
|
||||||
|
process.wait(3)
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
process.kill()
|
||||||
|
except ProcessLookupError:
|
||||||
|
return
|
||||||
|
|
||||||
|
with contextlib.suppress(subprocess.TimeoutExpired):
|
||||||
|
# give the process time to terminate
|
||||||
|
process.wait(3)
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def terminate_process(process: subprocess.Popen) -> Iterator[None]:
|
def terminate_process(process: subprocess.Popen) -> Iterator[None]:
|
||||||
try:
|
try:
|
||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
try:
|
_terminate_process(process)
|
||||||
process.terminate()
|
|
||||||
try:
|
|
||||||
with contextlib.suppress(subprocess.TimeoutExpired):
|
|
||||||
# give the process time to terminate
|
|
||||||
process.wait(3)
|
|
||||||
finally:
|
|
||||||
process.kill()
|
|
||||||
except ProcessLookupError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class TimeTable:
|
class TimeTable:
|
||||||
|
|||||||
Reference in New Issue
Block a user