cmd: wait on status after killing process

This commit is contained in:
Jörg Thalheim
2025-05-06 16:04:09 +02:00
parent 5ac4cc8586
commit b14c27c7bb

View File

@@ -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: