Skip to content

Commit 9492193

Browse files
authored
Merge pull request #210 from python-adaptive/lambda_check
raise an error when function is not pickleable and we are using the default executor.
2 parents 5db0f73 + 3a37f4b commit 9492193

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

adaptive/runner.py

Lines changed: 13 additions & 0 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
@@ -494,6 +495,18 @@ def __init__(
494495
def goal(_):
495496
return False
496497

498+
if executor is None and not inspect.iscoroutinefunction(learner.function):
499+
try:
500+
pickle.dumps(learner.function)
501+
except pickle.PicklingError:
502+
raise ValueError(
503+
"`learner.function` cannot be pickled (is it a lamdba function?)"
504+
" and therefore does not work with the default executor."
505+
" Either make sure the function is pickleble or use an executor"
506+
" that might work with 'hard to pickle'-functions"
507+
" , e.g. `ipyparallel` with `dill`."
508+
)
509+
497510
super().__init__(
498511
learner,
499512
goal,

0 commit comments

Comments
 (0)