mirror of
https://github.com/python/cpython.git
synced 2025-08-26 19:55:24 +00:00
bpo-36888: Add multiprocessing.parent_process() (GH-13247)
This commit is contained in:
parent
5ae1c84bcd
commit
c09a9f56c0
12 changed files with 155 additions and 20 deletions
|
@ -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():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue