sherpa-ai/sherpa

Can't pickle local object 'Flask.init..'

RalfKellner opened this issue · 3 comments

When running the code below, I get the error "Can't pickle local object 'Flask.init..'"

import sherpa
parameters = [sherpa.Discrete('num_units', [50, 200])]
alg = sherpa.algorithms.RandomSearch(max_num_trials=50)
study = sherpa.Study(parameters=parameters,
algorithm=alg,
lower_is_better=True)

Can you recommend me something which solves this error?

me too..
Traceback (most recent call last):
File "/Users/kennymccormick/github/QInvestment/Monitor_RPC_Client.py", line 16, in
study = sherpa.Study(parameters=parameters,
File "/Users/kennymccormick/opt/miniconda3/envs/scientific/lib/python3.9/site-packages/sherpa/core.py", line 109, in init
self.dashboard_process = self._run_web_server(dashboard_port)
File "/Users/kennymccormick/opt/miniconda3/envs/scientific/lib/python3.9/site-packages/sherpa/core.py", line 300, in _run_web_server
proc.start()
File "/Users/kennymccormick/opt/miniconda3/envs/scientific/lib/python3.9/multiprocessing/process.py", line 121, in start
self._popen = self._Popen(self)
File "/Users/kennymccormick/opt/miniconda3/envs/scientific/lib/python3.9/multiprocessing/context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "/Users/kennymccormick/opt/miniconda3/envs/scientific/lib/python3.9/multiprocessing/context.py", line 284, in _Popen
return Popen(process_obj)
File "/Users/kennymccormick/opt/miniconda3/envs/scientific/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 32, in init
super().init(process_obj)
File "/Users/kennymccormick/opt/miniconda3/envs/scientific/lib/python3.9/multiprocessing/popen_fork.py", line 19, in init
self._launch(process_obj)
File "/Users/kennymccormick/opt/miniconda3/envs/scientific/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 47, in _launch
reduction.dump(process_obj, fp)
File "/Users/kennymccormick/opt/miniconda3/envs/scientific/lib/python3.9/multiprocessing/reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'Flask.init..'

I had the same issue, interestingly enough I fixed it by reverting back to python 3.6. Hopefully, this works for you.

After 3 days, thanks g-d I found this
just add an import and a first line of code

from sherpa import multiprocessing

multiprocessing.set_start_method("fork")