(self, process_obj)
| 44 | method = 'spawn' |
| 45 | |
| 46 | def __init__(self, process_obj): |
| 47 | prep_data = spawn.get_preparation_data(process_obj._name) |
| 48 | |
| 49 | # read end of pipe will be duplicated by the child process |
| 50 | # -- see spawn_main() in spawn.py. |
| 51 | # |
| 52 | # bpo-33929: Previously, the read end of pipe was "stolen" by the child |
| 53 | # process, but it leaked a handle if the child process had been |
| 54 | # terminated before it could steal the handle from the parent process. |
| 55 | rhandle, whandle = _winapi.CreatePipe(None, 0) |
| 56 | wfd = msvcrt.open_osfhandle(whandle, 0) |
| 57 | cmd = spawn.get_command_line(parent_pid=os.getpid(), |
| 58 | pipe_handle=rhandle) |
| 59 | |
| 60 | python_exe = spawn.get_executable() |
| 61 | |
| 62 | # bpo-35797: When running in a venv, we bypass the redirect |
| 63 | # executor and launch our base Python. |
| 64 | if WINENV and _path_eq(python_exe, sys.executable): |
| 65 | cmd[0] = python_exe = sys._base_executable |
| 66 | env = os.environ.copy() |
| 67 | env["__PYVENV_LAUNCHER__"] = sys.executable |
| 68 | else: |
| 69 | env = None |
| 70 | |
| 71 | cmd = ' '.join('"%s"' % x for x in cmd) |
| 72 | |
| 73 | with open(wfd, 'wb', closefd=True) as to_child: |
| 74 | # start process |
| 75 | try: |
| 76 | hp, ht, pid, tid = _winapi.CreateProcess( |
| 77 | python_exe, cmd, |
| 78 | None, None, False, 0, env, None, |
| 79 | STARTUPINFO(dwFlags=STARTF_FORCEOFFFEEDBACK)) |
| 80 | _winapi.CloseHandle(ht) |
| 81 | except: |
| 82 | _winapi.CloseHandle(rhandle) |
| 83 | raise |
| 84 | |
| 85 | # set attributes of self |
| 86 | self.pid = pid |
| 87 | self.returncode = None |
| 88 | self._handle = hp |
| 89 | self.sentinel = int(hp) |
| 90 | self.finalizer = util.Finalize(self, _close_handles, |
| 91 | (self.sentinel, int(rhandle))) |
| 92 | |
| 93 | # send information to child |
| 94 | set_spawning_popen(self) |
| 95 | try: |
| 96 | reduction.dump(prep_data, to_child) |
| 97 | reduction.dump(process_obj, to_child) |
| 98 | finally: |
| 99 | set_spawning_popen(None) |
| 100 | |
| 101 | def duplicate_for_child(self, handle): |
| 102 | assert self is get_spawning_popen() |
nothing calls this directly
no test coverage detected