Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
Closed
Description
According toPEP-734, it should work as same asThreadPoolExecutor, but it looks not.
Code
importconcurrent.futuresfromconcurrent.futuresimportInterpreterPoolExecutor,ThreadPoolExecutordeffib(n):ifn<2:returnnreturnfib(n-1)+fib(n-2)withInterpreterPoolExecutor(max_workers=5)asexecutor:futures= {executor.submit(fib,n):nforninrange(10)}forfutureinconcurrent.futures.as_completed(futures):n=futures[future]data=future.result()print(f"fib({n}):{data}")
Execution (InterpreterPoolExecutor)
Exception:AttributeError: module '__main__' has no attribute 'fib'The above exception was the direct cause of the following exception:concurrent.interpreters.NotShareableError:object could not be unpickledThe above exception was the direct cause of the following exception:Traceback (most recent call last): File"/Users/xxxx/oss/cpython/op.py", line14, in<module> data= future.result() File"/Users/xxxx/oss/cpython/Lib/concurrent/futures/_base.py", line443, inresultreturnself.__get_result()~~~~~~~~~~~~~~~~~^^ File"/Users/xxxx/oss/cpython/Lib/concurrent/futures/_base.py", line395, in__get_resultraiseself._exception File"/Users/xxxx/oss/cpython/Lib/concurrent/futures/thread.py", line86, inrun result= ctx.run(self.task) File"/Users/denny.na/oss/cpython/Lib/concurrent/futures/interpreter.py", line85, inrunreturnself.interp.call(do_call,self.results,*task)~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File"/Users/xxxx/oss/cpython/Lib/concurrent/interpreters/__init__.py", line233, incallreturnself._call(callable, args, kwargs)~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^ File"/Users/xxxx/oss/cpython/Lib/concurrent/interpreters/__init__.py", line215, in_call res, excinfo= _interpreters.call(self._id,callable, args, kwargs,restrict=True)~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^concurrent.interpreters.NotShareableError:args not shareable
Execution (ThreadPoolExecutor)
fib(0): 0fib(7): 13fib(2): 1fib(6): 8fib(1): 1fib(4): 3fib(3): 2fib(5): 5fib(9): 34fib(8): 21
Metadata
Metadata
Assignees
Labels
Projects
Status
Done