Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
db463e3
Convert asyncio/tasks.py to async/await
asvetlov Dec 7, 2017
bdde875
Convert asyncio/queues.py to async/await
asvetlov Dec 7, 2017
a44c892
Convert asyncio/test_utils.py to async/await
asvetlov Dec 7, 2017
ee5ecc7
Convert asyncio/base_subprocess.py to async/await
asvetlov Dec 7, 2017
5654dcf
Convert asyncio/subprocess.py to async/await
asvetlov Dec 7, 2017
0038376
Convert asyncio/streams.py to async/await
asvetlov Dec 7, 2017
3e90af4
Fix comments
asvetlov Dec 7, 2017
ca9c418
Convert asyncio/locks.py to async/await
asvetlov Dec 7, 2017
c0ec04e
Convert asyncio.sleep to async def
asvetlov Dec 7, 2017
f6d230d
Add a comment
asvetlov Dec 8, 2017
251d990
Add missing news
asvetlov Dec 8, 2017
983552a
Convert stubs from AbstrctEventLoop to async functions
asvetlov Dec 8, 2017
618fcee
Convert subprocess_shell/subprocess_exec
asvetlov Dec 8, 2017
cfab76e
Convert connect_read_pipe/connect_write_pip to async/await syntax
asvetlov Dec 8, 2017
ee8c389
Convert create_datagram_endpoint
asvetlov Dec 8, 2017
ad64f0a
Convert create_unix_server/create_unix_connection
asvetlov Dec 8, 2017
cdd059a
Get rid of old style coroutines in unix_events.py
asvetlov Dec 8, 2017
b2c7d61
Convert selector_events.py to async/await
asvetlov Dec 8, 2017
a83deee
Convert wait_closed and create_connection
asvetlov Dec 8, 2017
0a355a5
Drop redundant line
asvetlov Dec 8, 2017
186f23a
Convert base_events.py
asvetlov Dec 8, 2017
6cc5056
Code cleanup
asvetlov Dec 8, 2017
6f15fa7
Drop redundant comments
asvetlov Dec 8, 2017
936b104
Fix indentation
asvetlov Dec 8, 2017
e339a2b
Add explicit tests for compatibility between old and new coroutines
asvetlov Dec 8, 2017
43eb968
Convert windows event loop to use async/await
asvetlov Dec 8, 2017
6ea4d75
Fix double awaiting of async function
asvetlov Dec 8, 2017
7c80c7c
Convert asyncio/locks.py
asvetlov Dec 8, 2017
1c0c2e5
Improve docstring
asvetlov Dec 8, 2017
d1a9a96
Convert tests to async/await
asvetlov Dec 8, 2017
17a5969
Convert more tests
asvetlov Dec 8, 2017
f159ca7
Convert more tests
asvetlov Dec 8, 2017
74cd8f3
Convert more tests
asvetlov Dec 8, 2017
19460e5
Convert tests
asvetlov Dec 8, 2017
61cf3eb
Improve test
asvetlov Dec 8, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Convert asyncio/queues.py to async/await
  • Loading branch information
asvetlov committed Dec 7, 2017
commit bdde875bb720107d4fa215eae0d2d17c46ead18e
17 changes: 7 additions & 10 deletions Lib/asyncio/queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Queue:
"""A queue, useful for coordinating producer and consumer coroutines.

If maxsize is less than or equal to zero, the queue size is infinite. If it
is an integer greater than 0, then "yield from put()" will block when the
is an integer greater than 0, then "await put()" will block when the
queue reaches maxsize, until an item is removed by get().

Unlike the standard library Queue, you can reliably know this Queue's size
Expand Down Expand Up @@ -116,8 +116,7 @@ def full(self):
else:
return self.qsize() >= self._maxsize

@coroutine
def put(self, item):
async def put(self, item):
"""Put an item into the queue.

Put an item into the queue. If the queue is full, wait until a free
Expand All @@ -129,7 +128,7 @@ def put(self, item):
putter = self._loop.create_future()
self._putters.append(putter)
try:
yield from putter
await putter
except:
putter.cancel() # Just in case putter is not done yet.
if not self.full() and not putter.cancelled():
Expand All @@ -151,8 +150,7 @@ def put_nowait(self, item):
self._finished.clear()
self._wakeup_next(self._getters)

@coroutine
def get(self):
async def get(self):
"""Remove and return an item from the queue.

If queue is empty, wait until an item is available.
Expand All @@ -163,7 +161,7 @@ def get(self):
getter = self._loop.create_future()
self._getters.append(getter)
try:
yield from getter
await getter
except:
getter.cancel() # Just in case getter is not done yet.

Expand Down Expand Up @@ -210,8 +208,7 @@ def task_done(self):
if self._unfinished_tasks == 0:
self._finished.set()

@coroutine
def join(self):
async def join(self):
"""Block until all items in the queue have been gotten and processed.

The count of unfinished tasks goes up whenever an item is added to the
Expand All @@ -220,7 +217,7 @@ def join(self):
When the count of unfinished tasks drops to zero, join() unblocks.
"""
if self._unfinished_tasks > 0:
yield from self._finished.wait()
await self._finished.wait()


class PriorityQueue(Queue):
Expand Down