cmd: wait on status after killing process

This commit is contained in:
Jörg Thalheim
2025-05-06 16:04:09 +02:00
parent 58c2cd8ffa
commit d8d0043249

View File

@@ -198,21 +198,33 @@ def terminate_process_group(process: subprocess.Popen) -> Iterator[None]:
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
def terminate_process(process: subprocess.Popen) -> Iterator[None]:
try:
yield
finally:
try:
process.terminate()
try:
with contextlib.suppress(subprocess.TimeoutExpired):
# give the process time to terminate
process.wait(3)
finally:
process.kill()
except ProcessLookupError:
pass
_terminate_process(process)
class TimeTable: