Skip to content

Commit e22b601

Browse files
committed
Better names: Worker → ChildProcessWrapper, func → target
1 parent d620613 commit e22b601

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

cuda_bindings/tests/run_python_code_safely.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class CompletedProcess:
2121
stderr: str
2222

2323

24-
class Worker:
25-
def __init__(self, result_queue, func, args, kwargs):
26-
self.func = func
24+
class ChildProcessWrapper:
25+
def __init__(self, result_queue, target, args, kwargs):
26+
self.target = target
2727
self.args = () if args is None else args
2828
self.kwargs = {} if kwargs is None else kwargs
2929
self.result_queue = result_queue
@@ -36,7 +36,7 @@ def __call__(self):
3636
sys.stderr = StringIO()
3737

3838
try:
39-
self.func(*self.args, **self.kwargs)
39+
self.target(*self.args, **self.kwargs)
4040
returncode = 0
4141
except SystemExit as e: # Handle sys.exit()
4242
returncode = e.code if isinstance(e.code, int) else 0
@@ -56,10 +56,10 @@ def __call__(self):
5656
pass
5757

5858

59-
def run_in_spawned_child_process(func, *, args=None, kwargs=None, timeout=None, rethrow=False):
60-
"""Run `func` in a spawned child process, capturing stdout/stderr.
59+
def run_in_spawned_child_process(target, *, args=None, kwargs=None, timeout=None, rethrow=False):
60+
"""Run `target` in a spawned child process, capturing stdout/stderr.
6161
62-
The provided `func` must be defined at the top level of a module, and must
62+
The provided `target` must be defined at the top level of a module, and must
6363
be importable in the spawned child process. Lambdas, closures, or interactively
6464
defined functions (e.g., in Jupyter notebooks) will not work.
6565
@@ -68,7 +68,7 @@ def run_in_spawned_child_process(func, *, args=None, kwargs=None, timeout=None,
6868
"""
6969
ctx = multiprocessing.get_context("spawn")
7070
result_queue = ctx.Queue()
71-
process = ctx.Process(target=Worker(result_queue, func, args, kwargs))
71+
process = ctx.Process(target=ChildProcessWrapper(result_queue, target, args, kwargs))
7272
process.start()
7373

7474
try:

0 commit comments

Comments
 (0)