mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
asyncio: sync with Tulip, add a new asyncio.coroutines module
This commit is contained in:
parent
61f32cb5b8
commit
f951d28ac8
12 changed files with 221 additions and 199 deletions
|
@ -26,9 +26,11 @@ import time
|
|||
import os
|
||||
import sys
|
||||
|
||||
from . import coroutines
|
||||
from . import events
|
||||
from . import futures
|
||||
from . import tasks
|
||||
from .coroutines import coroutine
|
||||
from .log import logger
|
||||
|
||||
|
||||
|
@ -118,7 +120,7 @@ class Server(events.AbstractServer):
|
|||
if not waiter.done():
|
||||
waiter.set_result(waiter)
|
||||
|
||||
@tasks.coroutine
|
||||
@coroutine
|
||||
def wait_closed(self):
|
||||
if self.sockets is None or self.waiters is None:
|
||||
return
|
||||
|
@ -175,7 +177,7 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
"""Create write pipe transport."""
|
||||
raise NotImplementedError
|
||||
|
||||
@tasks.coroutine
|
||||
@coroutine
|
||||
def _make_subprocess_transport(self, protocol, args, shell,
|
||||
stdin, stdout, stderr, bufsize,
|
||||
extra=None, **kwargs):
|
||||
|
@ -298,7 +300,7 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
|
||||
def call_at(self, when, callback, *args):
|
||||
"""Like call_later(), but uses an absolute time."""
|
||||
if tasks.iscoroutinefunction(callback):
|
||||
if coroutines.iscoroutinefunction(callback):
|
||||
raise TypeError("coroutines cannot be used with call_at()")
|
||||
if self._debug:
|
||||
self._assert_is_current_event_loop()
|
||||
|
@ -324,7 +326,7 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
return handle
|
||||
|
||||
def _call_soon(self, callback, args, check_loop):
|
||||
if tasks.iscoroutinefunction(callback):
|
||||
if coroutines.iscoroutinefunction(callback):
|
||||
raise TypeError("coroutines cannot be used with call_soon()")
|
||||
if self._debug and check_loop:
|
||||
self._assert_is_current_event_loop()
|
||||
|
@ -361,7 +363,7 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
return handle
|
||||
|
||||
def run_in_executor(self, executor, callback, *args):
|
||||
if tasks.iscoroutinefunction(callback):
|
||||
if coroutines.iscoroutinefunction(callback):
|
||||
raise TypeError("coroutines cannot be used with run_in_executor()")
|
||||
if isinstance(callback, events.Handle):
|
||||
assert not args
|
||||
|
@ -389,7 +391,7 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
def getnameinfo(self, sockaddr, flags=0):
|
||||
return self.run_in_executor(None, socket.getnameinfo, sockaddr, flags)
|
||||
|
||||
@tasks.coroutine
|
||||
@coroutine
|
||||
def create_connection(self, protocol_factory, host=None, port=None, *,
|
||||
ssl=None, family=0, proto=0, flags=0, sock=None,
|
||||
local_addr=None, server_hostname=None):
|
||||
|
@ -505,7 +507,7 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
sock, protocol_factory, ssl, server_hostname)
|
||||
return transport, protocol
|
||||
|
||||
@tasks.coroutine
|
||||
@coroutine
|
||||
def _create_connection_transport(self, sock, protocol_factory, ssl,
|
||||
server_hostname):
|
||||
protocol = protocol_factory()
|
||||
|
@ -521,7 +523,7 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
yield from waiter
|
||||
return transport, protocol
|
||||
|
||||
@tasks.coroutine
|
||||
@coroutine
|
||||
def create_datagram_endpoint(self, protocol_factory,
|
||||
local_addr=None, remote_addr=None, *,
|
||||
family=0, proto=0, flags=0):
|
||||
|
@ -593,7 +595,7 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
transport = self._make_datagram_transport(sock, protocol, r_addr)
|
||||
return transport, protocol
|
||||
|
||||
@tasks.coroutine
|
||||
@coroutine
|
||||
def create_server(self, protocol_factory, host=None, port=None,
|
||||
*,
|
||||
family=socket.AF_UNSPEC,
|
||||
|
@ -672,7 +674,7 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
self._start_serving(protocol_factory, sock, ssl, server)
|
||||
return server
|
||||
|
||||
@tasks.coroutine
|
||||
@coroutine
|
||||
def connect_read_pipe(self, protocol_factory, pipe):
|
||||
protocol = protocol_factory()
|
||||
waiter = futures.Future(loop=self)
|
||||
|
@ -680,7 +682,7 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
yield from waiter
|
||||
return transport, protocol
|
||||
|
||||
@tasks.coroutine
|
||||
@coroutine
|
||||
def connect_write_pipe(self, protocol_factory, pipe):
|
||||
protocol = protocol_factory()
|
||||
waiter = futures.Future(loop=self)
|
||||
|
@ -688,7 +690,7 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
yield from waiter
|
||||
return transport, protocol
|
||||
|
||||
@tasks.coroutine
|
||||
@coroutine
|
||||
def subprocess_shell(self, protocol_factory, cmd, *, stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||
universal_newlines=False, shell=True, bufsize=0,
|
||||
|
@ -706,7 +708,7 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
protocol, cmd, True, stdin, stdout, stderr, bufsize, **kwargs)
|
||||
return transport, protocol
|
||||
|
||||
@tasks.coroutine
|
||||
@coroutine
|
||||
def subprocess_exec(self, protocol_factory, program, *args,
|
||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE, universal_newlines=False,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue