MCPcopy Index your code
hub / github.com/python/cpython / _fixup_main_from_path

Function _fixup_main_from_path

Lib/multiprocessing/spawn.py:275–300  ·  view source on GitHub ↗
(main_path)

Source from the content-addressed store, hash-verified

273
274
275def _fixup_main_from_path(main_path):
276 # If this process was forked, __main__ may already be populated
277 current_main = sys.modules['__main__']
278
279 # Unfortunately, the main ipython launch script historically had no
280 # "if __name__ == '__main__'" guard, so we work around that
281 # by treating it like a __main__.py file
282 # See https://github.com/ipython/ipython/issues/4698
283 main_name = os.path.splitext(os.path.basename(main_path))[0]
284 if main_name == 'ipython':
285 return
286
287 # Otherwise, if __file__ already has the setting we expect,
288 # there's nothing more to do
289 if getattr(current_main, '__file__', None) == main_path:
290 return
291
292 # If the parent process has sent a path through rather than a module
293 # name we assume it is an executable script that may contain
294 # non-main code that needs to be executed
295 old_main_modules.append(current_main)
296 main_module = types.ModuleType("__mp_main__")
297 main_content = runpy.run_path(main_path,
298 run_name="__mp_main__")
299 main_module.__dict__.update(main_content)
300 sys.modules['__main__'] = sys.modules['__mp_main__'] = main_module
301
302
303def import_main_path(main_path):

Callers 2

prepareFunction · 0.85
import_main_pathFunction · 0.85

Calls 4

splitextMethod · 0.80
basenameMethod · 0.45
appendMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…