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

Function _execute_module

Lib/profiling/sampling/_sync_coordinator.py:129–149  ·  view source on GitHub ↗

Execute a Python module. Args: module_name: Name of the module to execute module_args: Arguments to pass to the module Raises: TargetError: If module cannot be found

(module_name: str, module_args: List[str])

Source from the content-addressed store, hash-verified

127
128
129def _execute_module(module_name: str, module_args: List[str]) -> None:
130 """
131 Execute a Python module.
132
133 Args:
134 module_name: Name of the module to execute
135 module_args: Arguments to pass to the module
136
137 Raises:
138 TargetError: If module cannot be found
139 """
140 # Replace sys.argv to match how Python normally runs modules
141 # When running 'python -m module args', sys.argv is ["__main__.py", "args"]
142 sys.argv = ["__main__.py"] + module_args
143
144 try:
145 runpy.run_module(module_name, run_name="__main__", alter_sys=True)
146 except ImportError as e:
147 raise TargetError(f"Module '{module_name}' not found: {e}") from e
148 # Let other exceptions (including SystemExit) propagate naturally
149 # so Python prints the full traceback to stderr
150
151
152def _execute_script(script_path: str, script_args: List[str], cwd: str) -> None:

Callers 1

mainFunction · 0.85

Calls 1

TargetErrorClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…