@@ -21,9 +21,9 @@ class CompletedProcess:
21
21
stderr : str
22
22
23
23
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
27
27
self .args = () if args is None else args
28
28
self .kwargs = {} if kwargs is None else kwargs
29
29
self .result_queue = result_queue
@@ -36,7 +36,7 @@ def __call__(self):
36
36
sys .stderr = StringIO ()
37
37
38
38
try :
39
- self .func (* self .args , ** self .kwargs )
39
+ self .target (* self .args , ** self .kwargs )
40
40
returncode = 0
41
41
except SystemExit as e : # Handle sys.exit()
42
42
returncode = e .code if isinstance (e .code , int ) else 0
@@ -56,10 +56,10 @@ def __call__(self):
56
56
pass
57
57
58
58
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.
61
61
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
63
63
be importable in the spawned child process. Lambdas, closures, or interactively
64
64
defined functions (e.g., in Jupyter notebooks) will not work.
65
65
@@ -68,7 +68,7 @@ def run_in_spawned_child_process(func, *, args=None, kwargs=None, timeout=None,
68
68
"""
69
69
ctx = multiprocessing .get_context ("spawn" )
70
70
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 ))
72
72
process .start ()
73
73
74
74
try :
0 commit comments