diff options
author | Antoine Pitrou <pitrou@free.fr> | 2017-06-24 17:22:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-24 17:22:23 (GMT) |
commit | 13e96cc596d158b98996db3fa291086ea4afecd9 (patch) | |
tree | e5d5abb7f5364b484ca4396ff99986ccac16ed0c /Lib/multiprocessing/forkserver.py | |
parent | 0ee32c148119031e19c79359f5c4789ee69fa355 (diff) | |
download | cpython-13e96cc596d158b98996db3fa291086ea4afecd9.zip cpython-13e96cc596d158b98996db3fa291086ea4afecd9.tar.gz cpython-13e96cc596d158b98996db3fa291086ea4afecd9.tar.bz2 |
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
Diffstat (limited to 'Lib/multiprocessing/forkserver.py')
-rw-r--r-- | Lib/multiprocessing/forkserver.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/Lib/multiprocessing/forkserver.py b/Lib/multiprocessing/forkserver.py index 7010515..b9f9b9d 100644 --- a/Lib/multiprocessing/forkserver.py +++ b/Lib/multiprocessing/forkserver.py @@ -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: |