From cc3c7b02869f9998305cbb01333d889112adda19 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 6 Jun 2022 21:11:55 +0530 Subject: [PATCH] Fix waitpid() call on python 3.8 --- kittens/prewarm/main.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/kittens/prewarm/main.py b/kittens/prewarm/main.py index 894b04bdc..de26aa04a 100644 --- a/kittens/prewarm/main.py +++ b/kittens/prewarm/main.py @@ -353,10 +353,11 @@ def main(args: List[str] = sys.argv) -> None: es = str(e).replace('\n', ' ') output_buf += f'ERR:{es}\n'.encode() else: - child_id = len(child_id_map) + 1 - child_id_map[child_id] = child_pid - child_ready_fds[child_id] = write_fd - output_buf += f'CHILD:{child_id}:{child_pid}\n'.encode() + if os.getpid() == self_pid: + child_id = len(child_id_map) + 1 + child_id_map[child_id] = child_pid + child_ready_fds[child_id] = write_fd + output_buf += f'CHILD:{child_id}:{child_pid}\n'.encode() finally: if os.getpid() == self_pid: os.close(read_fd) @@ -404,6 +405,10 @@ def main(args: List[str] = sys.argv) -> None: pid, exit_status = os.waitpid(-1, os.WNOHANG) except ChildProcessError: break + # a zero return means there is at least one child process + # existing and no exit status is available + if pid == 0: + break matched_child_id = -1 for child_id, child_pid in child_id_map.items(): if child_pid == pid: