File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change 22
33import functools
44import inspect
5+ import pickle
56from typing import Callable , Dict , Optional , Tuple
67
78
@@ -53,13 +54,12 @@ def __init__(
5354 if self .is_async :
5455 raise ValueError ("multiprocess cannot be True for an async task" )
5556
56- # The function needs to be globally accessible to be multiprocessed
57- # This excludes objects like lambdas and closures
58- # We capture these cases to throw a clear error message
59- module = inspect .getmodule (func )
60- if module is None or getattr (module , func .__name__ , None ) is not func :
61- raise RuntimeError (f"{ func } cannot be multiprocessed because it is not globally accessible"
62- f" -- it must be a globally defined object accessible by the name { func .__name__ } " )
57+ # The function must be picklable
58+ try :
59+ pickle .dumps (func )
60+ except (pickle .PicklingError , AttributeError ):
61+ raise RuntimeError (f"{ func } cannot be pickled and so cannot be multiprocessed"
62+ f" -- ensure that the function is globally accessible and that its definition has not changed" ) from None
6363
6464 self .func = func if bind is None else functools .partial (func , * bind [0 ], ** bind [1 ])
6565 self .branch = branch
You can’t perform that action at this time.
0 commit comments