MCPcopy Index your code
hub / github.com/RustPython/RustPython / connect_to_new_process

Method connect_to_new_process

Lib/multiprocessing/forkserver.py:77–104  ·  view source on GitHub ↗

Request forkserver to create a child process. Returns a pair of fds (status_r, data_w). The calling process can read the child process's pid and (eventually) its returncode from status_r. The calling process should write to data_w the pickled preparation and process

(self, fds)

Source from the content-addressed store, hash-verified

75 return self._inherited_fds
76
77 def connect_to_new_process(self, fds):
78 '''Request forkserver to create a child process.
79
80 Returns a pair of fds (status_r, data_w). The calling process can read
81 the child process's pid and (eventually) its returncode from status_r.
82 The calling process should write to data_w the pickled preparation and
83 process data.
84 '''
85 self.ensure_running()
86 if len(fds) + 4 >= MAXFDS_TO_SEND:
87 raise ValueError('too many fds')
88 with socket.socket(socket.AF_UNIX) as client:
89 client.connect(self._forkserver_address)
90 parent_r, child_w = os.pipe()
91 child_r, parent_w = os.pipe()
92 allfds = [child_r, child_w, self._forkserver_alive_fd,
93 resource_tracker.getfd()]
94 allfds += fds
95 try:
96 reduction.sendfds(client, allfds)
97 return parent_r, parent_w
98 except:
99 os.close(parent_r)
100 os.close(parent_w)
101 raise
102 finally:
103 os.close(child_r)
104 os.close(child_w)
105
106 def ensure_running(self):
107 '''Make sure that a fork server is running.

Callers 1

_launchMethod · 0.80

Calls 7

ensure_runningMethod · 0.95
lenFunction · 0.85
socketMethod · 0.80
connectMethod · 0.45
pipeMethod · 0.45
getfdMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected