mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-32193: Convert asyncio to async/await usage (#4753)
* Convert asyncio/tasks.py to async/await * Convert asyncio/queues.py to async/await * Convert asyncio/test_utils.py to async/await * Convert asyncio/base_subprocess.py to async/await * Convert asyncio/subprocess.py to async/await * Convert asyncio/streams.py to async/await * Fix comments * Convert asyncio/locks.py to async/await * Convert asyncio.sleep to async def * Add a comment * Add missing news * Convert stubs from AbstrctEventLoop to async functions * Convert subprocess_shell/subprocess_exec * Convert connect_read_pipe/connect_write_pip to async/await syntax * Convert create_datagram_endpoint * Convert create_unix_server/create_unix_connection * Get rid of old style coroutines in unix_events.py * Convert selector_events.py to async/await * Convert wait_closed and create_connection * Drop redundant line * Convert base_events.py * Code cleanup * Drop redundant comments * Fix indentation * Add explicit tests for compatibility between old and new coroutines * Convert windows event loop to use async/await * Fix double awaiting of async function * Convert asyncio/locks.py * Improve docstring * Convert tests to async/await * Convert more tests * Convert more tests * Convert more tests * Convert tests * Improve test
This commit is contained in:
parent
ede157331b
commit
5f841b5538
22 changed files with 647 additions and 771 deletions
|
@ -571,11 +571,10 @@ class StreamReaderTests(test_utils.TestCase):
|
|||
self.server = None
|
||||
self.loop = loop
|
||||
|
||||
@asyncio.coroutine
|
||||
def handle_client(self, client_reader, client_writer):
|
||||
data = yield from client_reader.readline()
|
||||
async def handle_client(self, client_reader, client_writer):
|
||||
data = await client_reader.readline()
|
||||
client_writer.write(data)
|
||||
yield from client_writer.drain()
|
||||
await client_writer.drain()
|
||||
client_writer.close()
|
||||
|
||||
def start(self):
|
||||
|
@ -608,14 +607,13 @@ class StreamReaderTests(test_utils.TestCase):
|
|||
self.loop.run_until_complete(self.server.wait_closed())
|
||||
self.server = None
|
||||
|
||||
@asyncio.coroutine
|
||||
def client(addr):
|
||||
reader, writer = yield from asyncio.open_connection(
|
||||
async def client(addr):
|
||||
reader, writer = await asyncio.open_connection(
|
||||
*addr, loop=self.loop)
|
||||
# send a line
|
||||
writer.write(b"hello world!\n")
|
||||
# read it back
|
||||
msgback = yield from reader.readline()
|
||||
msgback = await reader.readline()
|
||||
writer.close()
|
||||
return msgback
|
||||
|
||||
|
@ -645,11 +643,10 @@ class StreamReaderTests(test_utils.TestCase):
|
|||
self.loop = loop
|
||||
self.path = path
|
||||
|
||||
@asyncio.coroutine
|
||||
def handle_client(self, client_reader, client_writer):
|
||||
data = yield from client_reader.readline()
|
||||
async def handle_client(self, client_reader, client_writer):
|
||||
data = await client_reader.readline()
|
||||
client_writer.write(data)
|
||||
yield from client_writer.drain()
|
||||
await client_writer.drain()
|
||||
client_writer.close()
|
||||
|
||||
def start(self):
|
||||
|
@ -674,14 +671,13 @@ class StreamReaderTests(test_utils.TestCase):
|
|||
self.loop.run_until_complete(self.server.wait_closed())
|
||||
self.server = None
|
||||
|
||||
@asyncio.coroutine
|
||||
def client(path):
|
||||
reader, writer = yield from asyncio.open_unix_connection(
|
||||
async def client(path):
|
||||
reader, writer = await asyncio.open_unix_connection(
|
||||
path, loop=self.loop)
|
||||
# send a line
|
||||
writer.write(b"hello world!\n")
|
||||
# read it back
|
||||
msgback = yield from reader.readline()
|
||||
msgback = await reader.readline()
|
||||
writer.close()
|
||||
return msgback
|
||||
|
||||
|
@ -782,14 +778,13 @@ os.close(fd)
|
|||
clt, _ = sock.accept()
|
||||
clt.close()
|
||||
|
||||
@asyncio.coroutine
|
||||
def client(host, port):
|
||||
reader, writer = yield from asyncio.open_connection(
|
||||
async def client(host, port):
|
||||
reader, writer = await asyncio.open_connection(
|
||||
host, port, loop=self.loop)
|
||||
|
||||
while True:
|
||||
writer.write(b"foo\n")
|
||||
yield from writer.drain()
|
||||
await writer.drain()
|
||||
|
||||
# Start the server thread and wait for it to be listening.
|
||||
thread = threading.Thread(target=server)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue