MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / main

Function main

tools/python-3.11.9-amd64/Lib/multiprocessing/forkserver.py:167–296  ·  view source on GitHub ↗

Run forkserver.

(listener_fd, alive_r, preload, main_path=None, sys_path=None)

Source from the content-addressed store, hash-verified

165#
166
167def main(listener_fd, alive_r, preload, main_path=None, sys_path=None):
168 '''Run forkserver.'''
169 if preload:
170 if '__main__' in preload and main_path is not None:
171 process.current_process()._inheriting = True
172 try:
173 spawn.import_main_path(main_path)
174 finally:
175 del process.current_process()._inheriting
176 for modname in preload:
177 try:
178 __import__(modname)
179 except ImportError:
180 pass
181
182 util._close_stdin()
183
184 sig_r, sig_w = os.pipe()
185 os.set_blocking(sig_r, False)
186 os.set_blocking(sig_w, False)
187
188 def sigchld_handler(*_unused):
189 # Dummy signal handler, doesn't do anything
190 pass
191
192 handlers = {
193 # unblocking SIGCHLD allows the wakeup fd to notify our event loop
194 signal.SIGCHLD: sigchld_handler,
195 # protect the process from ^C
196 signal.SIGINT: signal.SIG_IGN,
197 }
198 old_handlers = {sig: signal.signal(sig, val)
199 for (sig, val) in handlers.items()}
200
201 # calling os.write() in the Python signal handler is racy
202 signal.set_wakeup_fd(sig_w)
203
204 # map child pids to client fds
205 pid_to_fd = {}
206
207 with socket.socket(socket.AF_UNIX, fileno=listener_fd) as listener, \
208 selectors.DefaultSelector() as selector:
209 _forkserver._forkserver_address = listener.getsockname()
210
211 selector.register(listener, selectors.EVENT_READ)
212 selector.register(alive_r, selectors.EVENT_READ)
213 selector.register(sig_r, selectors.EVENT_READ)
214
215 while True:
216 try:
217 while True:
218 rfds = [key.fileobj for (key, events) in selector.select()]
219 if rfds:
220 break
221
222 if alive_r in rfds:
223 # EOF because no more client processes left
224 assert os.read(alive_r, 1) == b'', "Not at EOF?"

Callers

nothing calls this directly

Calls 15

__import__Function · 0.85
write_signedFunction · 0.85
_serve_oneFunction · 0.85
socketMethod · 0.80
getsocknameMethod · 0.80
itemsMethod · 0.45
registerMethod · 0.45
selectMethod · 0.45
readMethod · 0.45
popMethod · 0.45
closeMethod · 0.45
warnMethod · 0.45

Tested by

no test coverage detected