Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

InterpreterPoolExecutor does not work as replacement of ThreadPoolExecutor. #136603

Closed
Assignees
ericsnowcurrently
Labels
3.14bugs and security fixesstdlibPython modules in the Lib dirtopic-subinterpreterstype-bugAn unexpected behavior, bug, or error
@corona10

Description

@corona10

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

Labels

3.14bugs and security fixesstdlibPython modules in the Lib dirtopic-subinterpreterstype-bugAn unexpected behavior, bug, or error

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp