Skip to content

Commit f3c5ea3

Browse files
committed
check if the function is pickleble
1 parent 4227330 commit f3c5ea3

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

adaptive/runner.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import concurrent.futures as concurrent
66
import inspect
77
import os
8+
import pickle
89
import sys
910
import time
1011
import traceback
@@ -495,13 +496,18 @@ def __init__(
495496
def goal(_):
496497
return False
497498

498-
if isinstance(learner.function, types.LambdaType) and executor is None:
499-
raise ValueError(
500-
"A lambda function cannot be pickled and "
501-
"therefore doesn't work with the default executor."
502-
"Either do not use a lamdba or use a framework that"
503-
" allows this, i.e. `ipyparallel` with `dill`."
504-
)
499+
if executor is None:
500+
if isinstance(learner.function, types.LambdaType):
501+
raise ValueError(
502+
"A lambda function cannot be pickled and "
503+
"therefore doesn't work with the default executor."
504+
"Either do not use a lamdba or use a framework that"
505+
" allows this, e.g. `ipyparallel` with `dill`."
506+
)
507+
try:
508+
pickle.dumps(learner.function)
509+
except pickle.PicklingError:
510+
raise ValueError("`learner.function` needs to be pickleble.")
505511

506512
super().__init__(
507513
learner,

0 commit comments

Comments
 (0)