From 0df5a6c6c8998dd8357e70876a15e4d9df0965fd Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 4 Jun 2022 14:14:24 +0530 Subject: [PATCH] Utility function to test if PID is alive --- kitty/utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kitty/utils.py b/kitty/utils.py index d82a47ade..1ce99abb2 100644 --- a/kitty/utils.py +++ b/kitty/utils.py @@ -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