Utility function to test if PID is alive

This commit is contained in:
Kovid Goyal 2022-06-04 14:14:24 +05:30
parent bf4dc6365a
commit 0df5a6c6c8
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -1002,3 +1002,13 @@ def less_version(less_exe: str = 'less') -> int:
if m is None:
raise ValueError(f'Invalid version string for less: {o}')
return int(m.group(1))
def is_pid_alive(pid: int) -> bool:
try:
os.kill(pid, 0)
except ProcessLookupError:
return False
except Exception:
pass
return True