Skip to content

Commit 4719b22

Browse files
committed
ChatGPT suggestions
1 parent e22b601 commit 4719b22

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

cuda_bindings/tests/run_python_code_safely.py renamed to cuda_bindings/tests/spawned_process_runner.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import traceback
88
from dataclasses import dataclass
99
from io import StringIO
10+
from typing import Any, Callable, Optional, Sequence
1011

1112
PROCESS_KILLED = -9
1213
PROCESS_NO_RESULT = -999
@@ -56,7 +57,14 @@ def __call__(self):
5657
pass
5758

5859

59-
def run_in_spawned_child_process(target, *, args=None, kwargs=None, timeout=None, rethrow=False):
60+
def run_in_spawned_child_process(
61+
target: Callable[..., None],
62+
*,
63+
args: Optional[Sequence[Any]] = None,
64+
kwargs: Optional[dict[str, Any]] = None,
65+
timeout: Optional[float] = None,
66+
rethrow: bool = False,
67+
) -> CompletedProcess:
6068
"""Run `target` in a spawned child process, capturing stdout/stderr.
6169
6270
The provided `target` must be defined at the top level of a module, and must
@@ -100,7 +108,8 @@ def run_in_spawned_child_process(target, *, args=None, kwargs=None, timeout=None
100108
if rethrow and result.returncode != 0:
101109
raise ChildProcessError(
102110
f"Child process exited with code {result.returncode}.\n"
103-
f"--- stderr-from-child-process ---\n{result.stderr}"
111+
"--- stderr-from-child-process ---\n"
112+
f"{result.stderr}"
104113
"<end-of-stderr-from-child-process>\n"
105114
)
106115

cuda_bindings/tests/test_path_finder_load.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66

77
import pytest
8-
import run_python_code_safely
8+
import spawned_process_runner
99

1010
from cuda.bindings import path_finder
1111
from cuda.bindings._path_finder import supported_libs
@@ -75,7 +75,7 @@ def test_find_or_load_nvidia_dynamic_library(info_summary_append, libname):
7575
# to ensure isolation of global dynamic linking state (e.g., dlopen handles).
7676
# Without child processes, loading/unloading libraries during testing could
7777
# interfere across test cases and lead to nondeterministic or platform-specific failures.
78-
result = run_python_code_safely.run_in_spawned_child_process(child_process_func, args=(libname,), timeout=30)
78+
result = spawned_process_runner.run_in_spawned_child_process(child_process_func, args=(libname,), timeout=30)
7979
if result.returncode == 0:
8080
info_summary_append(f"abs_path={result.stdout.rstrip()}")
8181
else:

0 commit comments

Comments
 (0)