mirror of
https://github.com/python/cpython.git
synced 2026-01-06 23:42:34 +00:00
bpo-32596: Lazy import concurrent.futures.process and thread (GH-5241)
This commit is contained in:
parent
338cd83c5d
commit
6690bb9f17
2 changed files with 37 additions and 2 deletions
|
|
@ -15,5 +15,36 @@
|
|||
Executor,
|
||||
wait,
|
||||
as_completed)
|
||||
from concurrent.futures.process import ProcessPoolExecutor
|
||||
from concurrent.futures.thread import ThreadPoolExecutor
|
||||
|
||||
__all__ = (
|
||||
'FIRST_COMPLETED',
|
||||
'FIRST_EXCEPTION',
|
||||
'ALL_COMPLETED',
|
||||
'CancelledError',
|
||||
'TimeoutError',
|
||||
'BrokenExecutor',
|
||||
'Future',
|
||||
'Executor',
|
||||
'wait',
|
||||
'as_completed',
|
||||
'ProcessPoolExecutor',
|
||||
'ThreadPoolExecutor',
|
||||
)
|
||||
|
||||
|
||||
def __dir__():
|
||||
return __all__ + ('__author__', '__doc__')
|
||||
|
||||
|
||||
def __getattr__(name):
|
||||
global ProcessPoolExecutor, ThreadPoolExecutor
|
||||
|
||||
if name == 'ProcessPoolExecutor':
|
||||
from .process import ProcessPoolExecutor
|
||||
return ProcessPoolExecutor
|
||||
|
||||
if name == 'ThreadPoolExecutor':
|
||||
from .thread import ThreadPoolExecutor
|
||||
return ThreadPoolExecutor
|
||||
|
||||
raise AttributeError(f"module {__name__} has no attribute {name}")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
``concurrent.futures`` imports ``ThreadPoolExecutor`` and
|
||||
``ProcessPoolExecutor`` lazily (using :pep:`562`).
|
||||
It makes ``import asyncio`` about 15% faster because asyncio
|
||||
uses only ``ThreadPoolExecutor`` by default.
|
||||
Loading…
Add table
Add a link
Reference in a new issue