asyncio: add asyncio.threads for py39 (#4136)

This commit is contained in:
Shantanu
2020-05-28 13:37:46 -07:00
committed by GitHub
parent 0bed1d3956
commit feb43f7237
6 changed files with 104 additions and 98 deletions

View File

@@ -1,57 +1,12 @@
import sys
from typing import Type
from asyncio.base_events import BaseEventLoop as BaseEventLoop
from asyncio.coroutines import (
coroutine as coroutine,
iscoroutinefunction as iscoroutinefunction,
iscoroutine as iscoroutine,
)
from asyncio.protocols import (
BaseProtocol as BaseProtocol,
Protocol as Protocol,
DatagramProtocol as DatagramProtocol,
SubprocessProtocol as SubprocessProtocol,
)
if sys.version_info >= (3, 7):
from asyncio.protocols import BufferedProtocol as BufferedProtocol
from asyncio.streams import (
StreamReader as StreamReader,
StreamWriter as StreamWriter,
StreamReaderProtocol as StreamReaderProtocol,
open_connection as open_connection,
start_server as start_server,
)
from asyncio.subprocess import (
create_subprocess_exec as create_subprocess_exec,
create_subprocess_shell as create_subprocess_shell,
)
from asyncio.transports import (
BaseTransport as BaseTransport,
ReadTransport as ReadTransport,
WriteTransport as WriteTransport,
Transport as Transport,
DatagramTransport as DatagramTransport,
SubprocessTransport as SubprocessTransport,
)
from asyncio.futures import (
Future as Future,
wrap_future as wrap_future,
)
from asyncio.tasks import (
FIRST_COMPLETED as FIRST_COMPLETED,
FIRST_EXCEPTION as FIRST_EXCEPTION,
ALL_COMPLETED as ALL_COMPLETED,
as_completed as as_completed,
ensure_future as ensure_future,
gather as gather,
run_coroutine_threadsafe as run_coroutine_threadsafe,
shield as shield,
sleep as sleep,
wait as wait,
wait_for as wait_for,
Task as Task,
)
from asyncio.base_events import BaseEventLoop as BaseEventLoop
from asyncio.events import (
AbstractEventLoopPolicy as AbstractEventLoopPolicy,
AbstractEventLoop as AbstractEventLoop,
@@ -65,59 +20,11 @@ from asyncio.events import (
new_event_loop as new_event_loop,
get_child_watcher as get_child_watcher,
set_child_watcher as set_child_watcher,
)
from asyncio.queues import (
Queue as Queue,
PriorityQueue as PriorityQueue,
LifoQueue as LifoQueue,
QueueFull as QueueFull,
QueueEmpty as QueueEmpty,
)
from asyncio.locks import (
Lock as Lock,
Event as Event,
Condition as Condition,
Semaphore as Semaphore,
BoundedSemaphore as BoundedSemaphore,
)
from asyncio.futures import isfuture as isfuture
from asyncio.events import (
_set_running_loop as _set_running_loop,
_get_running_loop as _get_running_loop,
)
if sys.platform == 'win32':
from asyncio.windows_events import *
else:
from asyncio.streams import (
open_unix_connection as open_unix_connection,
start_unix_server as start_unix_server,
)
DefaultEventLoopPolicy: Type[AbstractEventLoopPolicy]
if sys.version_info >= (3, 7):
from asyncio.events import (
get_running_loop as get_running_loop,
)
from asyncio.tasks import (
all_tasks as all_tasks,
create_task as create_task,
current_task as current_task,
)
from asyncio.runners import (
run as run,
)
if sys.platform != 'win32':
from .unix_events import (
AbstractChildWatcher as AbstractChildWatcher,
FastChildWatcher as FastChildWatcher,
SafeChildWatcher as SafeChildWatcher,
SelectorEventLoop as SelectorEventLoop,
)
if sys.version_info >= (3, 8):
from .unix_events import MultiLoopChildWatcher as MultiLoopChildWatcher, ThreadedChildWatcher as ThreadedChildWatcher
from asyncio.events import get_running_loop as get_running_loop
if sys.version_info >= (3, 8):
from asyncio.exceptions import (
CancelledError as CancelledError,
@@ -141,3 +48,91 @@ else:
IncompleteReadError as IncompleteReadError,
LimitOverrunError as LimitOverrunError,
)
from asyncio.futures import (
Future as Future,
isfuture as isfuture,
wrap_future as wrap_future,
)
from asyncio.locks import (
Lock as Lock,
Event as Event,
Condition as Condition,
Semaphore as Semaphore,
BoundedSemaphore as BoundedSemaphore,
)
from asyncio.protocols import (
BaseProtocol as BaseProtocol,
Protocol as Protocol,
DatagramProtocol as DatagramProtocol,
SubprocessProtocol as SubprocessProtocol,
)
if sys.version_info >= (3, 7):
from asyncio.protocols import BufferedProtocol as BufferedProtocol
from asyncio.queues import (
Queue as Queue,
PriorityQueue as PriorityQueue,
LifoQueue as LifoQueue,
QueueFull as QueueFull,
QueueEmpty as QueueEmpty,
)
if sys.version_info >= (3, 7):
from asyncio.runners import run as run
from asyncio.streams import (
StreamReader as StreamReader,
StreamWriter as StreamWriter,
StreamReaderProtocol as StreamReaderProtocol,
open_connection as open_connection,
start_server as start_server,
)
from asyncio.subprocess import (
create_subprocess_exec as create_subprocess_exec,
create_subprocess_shell as create_subprocess_shell,
)
from asyncio.tasks import (
FIRST_COMPLETED as FIRST_COMPLETED,
FIRST_EXCEPTION as FIRST_EXCEPTION,
ALL_COMPLETED as ALL_COMPLETED,
as_completed as as_completed,
ensure_future as ensure_future,
gather as gather,
run_coroutine_threadsafe as run_coroutine_threadsafe,
shield as shield,
sleep as sleep,
wait as wait,
wait_for as wait_for,
Task as Task,
)
if sys.version_info >= (3, 7):
from asyncio.tasks import (
all_tasks as all_tasks,
create_task as create_task,
current_task as current_task,
)
if sys.version_info >= (3, 9):
from asyncio.threads import to_thread as to_thread
from asyncio.transports import (
BaseTransport as BaseTransport,
ReadTransport as ReadTransport,
WriteTransport as WriteTransport,
Transport as Transport,
DatagramTransport as DatagramTransport,
SubprocessTransport as SubprocessTransport,
)
DefaultEventLoopPolicy: Type[AbstractEventLoopPolicy]
if sys.platform == 'win32':
from asyncio.windows_events import *
if sys.platform != 'win32':
from asyncio.streams import (
open_unix_connection as open_unix_connection,
start_unix_server as start_unix_server,
)
from .unix_events import (
AbstractChildWatcher as AbstractChildWatcher,
FastChildWatcher as FastChildWatcher,
SafeChildWatcher as SafeChildWatcher,
SelectorEventLoop as SelectorEventLoop,
)
if sys.version_info >= (3, 8):
from .unix_events import MultiLoopChildWatcher as MultiLoopChildWatcher, ThreadedChildWatcher as ThreadedChildWatcher

View File

@@ -0,0 +1,7 @@
import sys
from typing import Any, Callable, TypeVar
_T = TypeVar('_T')
if sys.version_info >= (3, 9):
async def to_thread(__func: Callable[..., _T], *args: Any, **kwargs: Any) -> _T: ...

View File

@@ -4,7 +4,7 @@ asyncio.Future._loop
asyncio.Future._tb_logger
asyncio.Task.__init__
asyncio.Task._wakeup
asyncio.exceptions
asyncio.exceptions # Added in Python 3.8
asyncio.futures.Future._callbacks
asyncio.futures.Future._exception
asyncio.futures.Future._loop
@@ -13,6 +13,7 @@ asyncio.futures._TracebackLogger.__init__
asyncio.runners
asyncio.tasks.Task.__init__
asyncio.tasks.Task._wakeup
asyncio.threads # Added in Python 3.9
bdb.GENERATOR_AND_COROUTINE_FLAGS
builtins.str.maketrans
cmath.log

View File

@@ -1,8 +1,9 @@
asyncio.Future.__init__
asyncio.exceptions
asyncio.exceptions # Added in Python 3.8
asyncio.futures.Future.__init__
asyncio.futures._TracebackLogger.__init__
asyncio.runners
asyncio.threads # Added in Python 3.9
builtins.str.maketrans
cmath.log
codecs.StreamRecoder.seek

View File

@@ -6,9 +6,10 @@ asyncio.TimerHandle.__init__
asyncio.events.AbstractEventLoop.sock_sendfile
asyncio.events.Handle.__init__
asyncio.events.TimerHandle.__init__
asyncio.exceptions
asyncio.exceptions # Added in Python 3.8
asyncio.futures.Future.__init__
asyncio.futures.Future._callbacks
asyncio.threads # Added in Python 3.9
builtins.dict.get
builtins.reversed
builtins.str.maketrans

View File

@@ -16,6 +16,7 @@ asyncio.events.TimerHandle.__init__
asyncio.futures.Future.__init__
asyncio.futures.Future._callbacks
asyncio.proactor_events._ProactorBasePipeTransport.__del__
asyncio.threads # Added in Python 3.9
builtins.compile
builtins.dict.get
builtins.reversed