Use a map for pid -> socketchild

This commit is contained in:
Kovid Goyal 2022-07-02 14:02:07 +05:30
parent c7718d078c
commit 44c9d66dd4
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -468,6 +468,7 @@ def main(stdin_fd: int, stdout_fd: int, notify_child_death_fd: int, unix_socket:
input_buf = output_buf = child_death_buf = b'' input_buf = output_buf = child_death_buf = b''
child_ready_fds: Dict[int, int] = {} child_ready_fds: Dict[int, int] = {}
child_pid_map: Dict[int, int] = {} child_pid_map: Dict[int, int] = {}
socket_pid_map: Dict[int, SocketChild] = {}
socket_children: Dict[int, SocketChild] = {} socket_children: Dict[int, SocketChild] = {}
child_id_counter = count() child_id_counter = count()
self_pid = os.getpid() self_pid = os.getpid()
@ -584,10 +585,9 @@ def main(stdin_fd: int, stdout_fd: int, notify_child_death_fd: int, unix_socket:
break break
child_id = child_pid_map.pop(pid, None) child_id = child_pid_map.pop(pid, None)
if child_id is None: if child_id is None:
for sc in socket_children.values(): sc = socket_pid_map.pop(pid, None)
if sc.pid == pid: if sc is not None:
sc.handle_death(status) sc.handle_death(status)
break
else: else:
handle_child_death(child_id, pid) handle_child_death(child_id, pid)
@ -624,8 +624,8 @@ def main(stdin_fd: int, stdout_fd: int, notify_child_death_fd: int, unix_socket:
try: try:
if scq.read(): if scq.read():
poll.unregister(scq.fd) poll.unregister(scq.fd)
scq.conn.shutdown(socket.SHUT_RD)
scq.fork(get_all_non_child_fds()) scq.fork(get_all_non_child_fds())
socket_pid_map[scq.pid] = scq
scq.child_id = next(child_id_counter) scq.child_id = next(child_id_counter)
except SocketClosed: except SocketClosed:
socket_children.pop(q) socket_children.pop(q)