Run a Python file in a subprocess with built librt available. This runs the file in a fresh Python process where the built librt is at the front of sys.path, avoiding conflicts with any system librt. Args: file_path: Path to Python file to execute. experimental: Whether
(
file_path: str, experimental: bool = True, check: bool = True, opt_level: str = "0"
)
| 209 | |
| 210 | |
| 211 | def run_with_librt( |
| 212 | file_path: str, experimental: bool = True, check: bool = True, opt_level: str = "0" |
| 213 | ) -> subprocess.CompletedProcess[str]: |
| 214 | """Run a Python file in a subprocess with built librt available. |
| 215 | |
| 216 | This runs the file in a fresh Python process where the built librt |
| 217 | is at the front of sys.path, avoiding conflicts with any system librt. |
| 218 | |
| 219 | Args: |
| 220 | file_path: Path to Python file to execute. |
| 221 | experimental: Whether to use experimental features. |
| 222 | check: If True, raise CalledProcessError on non-zero exit. |
| 223 | opt_level: Optimization level ("0".."3") used when building librt. |
| 224 | |
| 225 | Returns: |
| 226 | CompletedProcess with stdout, stderr, and returncode. |
| 227 | """ |
| 228 | librt_path = get_librt_path(experimental, opt_level=opt_level) |
| 229 | # Prepend librt path to PYTHONPATH |
| 230 | env = os.environ.copy() |
| 231 | existing = env.get("PYTHONPATH", "") |
| 232 | env["PYTHONPATH"] = librt_path + (os.pathsep + existing if existing else "") |
| 233 | |
| 234 | return subprocess.run( |
| 235 | [sys.executable, file_path], capture_output=True, text=True, check=check, env=env |
| 236 | ) |
nothing calls this directly
no test coverage detected
searching dependent graphs…