Skip to content

Commit 6ed4774

Browse files
committed
Fix import behavior for concurrent.futures.InterpreterPoolExecutor
1 parent b7aa2a4 commit 6ed4774

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

Lib/concurrent/futures/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ def __dir__():
3939
return __all__ + ('__author__', '__doc__')
4040

4141

42+
_no_interpreter_pool_executor = False
43+
44+
4245
def __getattr__(name):
4346
global ProcessPoolExecutor, ThreadPoolExecutor, InterpreterPoolExecutor
47+
global _no_interpreter_pool_executor
4448

4549
if name == 'ProcessPoolExecutor':
4650
from .process import ProcessPoolExecutor as pe
@@ -52,13 +56,13 @@ def __getattr__(name):
5256
ThreadPoolExecutor = te
5357
return te
5458

55-
if name == 'InterpreterPoolExecutor':
59+
if name == 'InterpreterPoolExecutor' and not _no_interpreter_pool_executor:
5660
try:
5761
from .interpreter import InterpreterPoolExecutor as ie
5862
except ModuleNotFoundError:
59-
ie = InterpreterPoolExecutor = None
63+
_no_interpreter_pool_executor = True
6064
else:
6165
InterpreterPoolExecutor = ie
62-
return ie
66+
return ie
6367

6468
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Raises :exc:`AttributeError` when accessing
2+
``concurrent.futures.InterpreterPoolExecutor`` and :mod:`_interpreter` is
3+
not available.

0 commit comments

Comments
 (0)