Fix waitpid() call on python 3.8

This commit is contained in:
Kovid Goyal 2022-06-06 21:11:55 +05:30
parent bf6c90a69a
commit cc3c7b0286
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -353,10 +353,11 @@ def main(args: List[str] = sys.argv) -> None:
es = str(e).replace('\n', ' ') es = str(e).replace('\n', ' ')
output_buf += f'ERR:{es}\n'.encode() output_buf += f'ERR:{es}\n'.encode()
else: else:
child_id = len(child_id_map) + 1 if os.getpid() == self_pid:
child_id_map[child_id] = child_pid child_id = len(child_id_map) + 1
child_ready_fds[child_id] = write_fd child_id_map[child_id] = child_pid
output_buf += f'CHILD:{child_id}:{child_pid}\n'.encode() child_ready_fds[child_id] = write_fd
output_buf += f'CHILD:{child_id}:{child_pid}\n'.encode()
finally: finally:
if os.getpid() == self_pid: if os.getpid() == self_pid:
os.close(read_fd) os.close(read_fd)
@ -404,6 +405,10 @@ def main(args: List[str] = sys.argv) -> None:
pid, exit_status = os.waitpid(-1, os.WNOHANG) pid, exit_status = os.waitpid(-1, os.WNOHANG)
except ChildProcessError: except ChildProcessError:
break 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 matched_child_id = -1
for child_id, child_pid in child_id_map.items(): for child_id, child_pid in child_id_map.items():
if child_pid == pid: if child_pid == pid: