diff options
author | Thomas Moreau <thomas.moreau.2010@gmail.com> | 2019-05-20 19:37:05 (GMT) |
---|---|---|
committer | Antoine Pitrou <antoine@python.org> | 2019-05-20 19:37:05 (GMT) |
commit | c09a9f56c08d80567454cae6f78f738a89e1ae94 (patch) | |
tree | 7f00233cfa994ba74ca952d371ae85651690602a /Lib/multiprocessing/spawn.py | |
parent | 5ae1c84bcd13b766989fc3f1e1c851e7bd4c1faa (diff) | |
download | cpython-c09a9f56c08d80567454cae6f78f738a89e1ae94.zip cpython-c09a9f56c08d80567454cae6f78f738a89e1ae94.tar.gz cpython-c09a9f56c08d80567454cae6f78f738a89e1ae94.tar.bz2 |
bpo-36888: Add multiprocessing.parent_process() (GH-13247)
Diffstat (limited to 'Lib/multiprocessing/spawn.py')
-rw-r--r-- | Lib/multiprocessing/spawn.py | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/Lib/multiprocessing/spawn.py b/Lib/multiprocessing/spawn.py index f66b5aa..7cc129e 100644 --- a/Lib/multiprocessing/spawn.py +++ b/Lib/multiprocessing/spawn.py @@ -100,25 +100,24 @@ def spawn_main(pipe_handle, parent_pid=None, tracker_fd=None): if parent_pid is not None: source_process = _winapi.OpenProcess( - _winapi.PROCESS_DUP_HANDLE, False, parent_pid) + _winapi.SYNCHRONIZE | _winapi.PROCESS_DUP_HANDLE, + False, parent_pid) else: source_process = None - try: - new_handle = reduction.duplicate(pipe_handle, - source_process=source_process) - finally: - if source_process is not None: - _winapi.CloseHandle(source_process) + new_handle = reduction.duplicate(pipe_handle, + source_process=source_process) fd = msvcrt.open_osfhandle(new_handle, os.O_RDONLY) + parent_sentinel = source_process else: from . import resource_tracker resource_tracker._resource_tracker._fd = tracker_fd fd = pipe_handle - exitcode = _main(fd) + parent_sentinel = os.dup(pipe_handle) + exitcode = _main(fd, parent_sentinel) sys.exit(exitcode) -def _main(fd): +def _main(fd, parent_sentinel): with os.fdopen(fd, 'rb', closefd=True) as from_parent: process.current_process()._inheriting = True try: @@ -127,7 +126,7 @@ def _main(fd): self = reduction.pickle.load(from_parent) finally: del process.current_process()._inheriting - return self._bootstrap() + return self._bootstrap(parent_sentinel) def _check_not_importing_main(): |