Fix bpo-30596: Add close() method to multiprocessing.Process (#2010)

* Fix bpo-30596: Add close() method to multiprocessing.Process

* Raise ValueError if close() is called before the Process is finished running

* Add docs

* Add NEWS blurb
This commit is contained in:
Antoine Pitrou 2017-06-24 19:22:23 +02:00 committed by GitHub
parent 0ee32c1481
commit 13e96cc596
9 changed files with 106 additions and 8 deletions

View file

@ -210,8 +210,12 @@ def main(listener_fd, alive_r, preload, main_path=None, sys_path=None):
else:
assert os.WIFEXITED(sts)
returncode = os.WEXITSTATUS(sts)
# Write the exit code to the pipe
write_signed(child_w, returncode)
# Send exit code to client process
try:
write_signed(child_w, returncode)
except BrokenPipeError:
# client vanished
pass
os.close(child_w)
else:
# This shouldn't happen really
@ -241,8 +245,12 @@ def main(listener_fd, alive_r, preload, main_path=None, sys_path=None):
finally:
os._exit(code)
else:
# Send pid to client processes
write_signed(child_w, pid)
# Send pid to client process
try:
write_signed(child_w, pid)
except BrokenPipeError:
# client vanished
pass
pid_to_fd[pid] = child_w
os.close(child_r)
for fd in fds: