shell_command: handle ProcessLookupError when cancelling

This suggests that the process has previously exited.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2021-11-01 08:25:28 -04:00
parent e71e723f89
commit 4f43cf3a9f
1 changed files with 3 additions and 1 deletions

View File

@ -85,12 +85,14 @@ class SCProcess(asyncio.subprocess.Process):
sig_idx = min(2, max(0, sig_idx))
sigs = [signal.SIGINT, signal.SIGTERM, signal.SIGKILL][sig_idx:]
for sig in sigs:
self.send_signal(sig)
try:
self.send_signal(sig)
ret = self.wait()
await asyncio.wait_for(ret, timeout=2.)
except asyncio.TimeoutError:
continue
except ProcessLookupError:
pass
logging.debug(f"Command '{self.program_name}' exited with "
f"signal: {sig.name}")
exit_success = True