File tree 1 file changed +7
-7
lines changed
1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import functools
4
4
import inspect
5
+ import pickle
5
6
from typing import Callable , Dict , Optional , Tuple
6
7
7
8
@@ -53,13 +54,12 @@ def __init__(
53
54
if self .is_async :
54
55
raise ValueError ("multiprocess cannot be True for an async task" )
55
56
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
63
63
64
64
self .func = func if bind is None else functools .partial (func , * bind [0 ], ** bind [1 ])
65
65
self .branch = branch
You can’t perform that action at this time.
0 commit comments