◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
15 changes: 13 additions & 2 deletions Lib/multiprocessing/popen_spawn_win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
WINEXE = (sys.platform == 'win32' and getattr(sys, 'frozen', False))
WINSERVICE = sys.executable.lower().endswith("pythonservice.exe")

#
# We define a Popen class similar to the one from subprocess, but
# whose constructor takes a process object as its argument.
Expand All @@ -32,8 +38,12 @@ class Popen(object):
def __init__(self, process_obj):
prep_data = spawn.get_preparation_data(process_obj._name)

# read end of pipe will be "stolen" by the child process
# -- see spawn_main() in spawn.py.
rhandle, whandle = _winapi.CreatePipe(None, 0)
wfd = msvcrt.open_osfhandle(whandle, 0)
cmd = spawn.get_command_line(parent_pid=os.getpid(),
Expand All @@ -56,7 +66,8 @@ def __init__(self, process_obj):
self.returncode = None
self._handle = hp
self.sentinel = int(hp)
self.finalizer = util.Finalize(self, _winapi.CloseHandle, (self.sentinel,))

# send information to child
set_spawning_popen(self)
Expand Down
10 changes: 7 additions & 3 deletions Lib/multiprocessing/reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,16 @@ def dump(obj, file, protocol=None):
__all__ += ['DupHandle', 'duplicate', 'steal_handle']
import _winapi

def duplicate(handle, target_process=None, inheritable=False):
'''Duplicate a handle. (target_process is a handle not a pid!)'''
if target_process is None:
target_process = _winapi.GetCurrentProcess()
return _winapi.DuplicateHandle(
_winapi.GetCurrentProcess(), handle, target_process,
0, inheritable, _winapi.DUPLICATE_SAME_ACCESS)

def steal_handle(source_pid, handle):
Expand Down
10 changes: 9 additions & 1 deletion Lib/multiprocessing/spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,15 @@ def spawn_main(pipe_handle, parent_pid=None, tracker_fd=None):
assert is_forking(sys.argv), "Not forking"
if sys.platform == 'win32':
import msvcrt
new_handle = reduction.steal_handle(parent_pid, pipe_handle)
fd = msvcrt.open_osfhandle(new_handle, os.O_RDONLY)
else:
from . import semaphore_tracker
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Toggle all file notes Toggle all file annotations