MCPcopy Create free account
hub / github.com/tox-dev/filelock / run_fork_script

Function run_fork_script

tests/sqlite/process_support.py:82–102  ·  view source on GitHub ↗
(script: str, arguments: list[str], *, timeout: float)

Source from the content-addressed store, hash-verified

80
81
82def run_fork_script(script: str, arguments: list[str], *, timeout: float) -> _ForkResult:
83 process = subprocess.Popen( # executes this test's fixed interpreter and source
84 [sys.executable, "-c", script, *arguments],
85 start_new_session=True,
86 stderr=subprocess.PIPE,
87 stdout=subprocess.PIPE,
88 text=True,
89 )
90 try:
91 process_output, process_error = process.communicate(timeout=timeout)
92 except subprocess.TimeoutExpired as error:
93 with contextlib.suppress(ProcessLookupError):
94 if sys.platform == "win32": # pragma: win32 cover
95 process.kill()
96 else: # pragma: win32 no cover
97 os.killpg(process.pid, signal.SIGKILL)
98 process_output, process_error = process.communicate()
99 msg = f"fork script exceeded {timeout} seconds: stdout={process_output!r}, stderr={process_error!r}"
100 raise AssertionError(msg) from error
101 assert process.returncode is not None # pragma: needs fork
102 return _ForkResult(process.returncode, process_output, process_error) # pragma: needs fork
103
104
105class _ForkResult(NamedTuple):

Calls 1

_ForkResultClass · 0.85