From 7113580db23d83cb5420584541f6c743fa68b095 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 13 Jun 2022 02:19:51 +0530 Subject: [PATCH] macOS has no waitid Le Sigh --- kitty/prewarm.py | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/kitty/prewarm.py b/kitty/prewarm.py index f7437fcbf..794626291 100644 --- a/kitty/prewarm.py +++ b/kitty/prewarm.py @@ -45,18 +45,32 @@ class Child: child_process_pid: int -def wait_for_child_death(child_pid: int, timeout: float = 1) -> Optional[int]: - st = time.monotonic() - while time.monotonic() - st < timeout: - try: - x = os.waitid(os.P_PID, child_pid, os.WEXITED | os.WNOHANG) - except ChildProcessError: - return 0 - else: - if x is not None and x.si_pid == child_pid: - return x.si_status - time.sleep(0.01) - return None +if hasattr(os, 'waitid'): + def wait_for_child_death(child_pid: int, timeout: float = 1) -> Optional[int]: + st = time.monotonic() + while time.monotonic() - st < timeout: + try: + x = os.waitid(os.P_PID, child_pid, os.WEXITED | os.WNOHANG) + except ChildProcessError: + return 0 + else: + if x is not None and x.si_pid == child_pid: + return x.si_status + time.sleep(0.01) + return None +else: + def wait_for_child_death(child_pid: int, timeout: float = 1) -> Optional[int]: + st = time.monotonic() + while time.monotonic() - st < timeout: + try: + pid, status = os.waitpid(child_pid, os.WNOHANG) + except ChildProcessError: + return 0 + else: + if pid == child_pid: + return status + time.sleep(0.01) + return None class PrewarmProcess: