summaryrefslogtreecommitdiff
path: root/Lib/asyncio/queues.py
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2017-12-09 00:23:48 +0200
committerGitHub <noreply@github.com>2017-12-09 00:23:48 +0200
commit5f841b553814969220b096a2b4f959b7f6fcbaf6 (patch)
treeb48ea916d9585efa9bf7ff370b50c4e2dfb30247 /Lib/asyncio/queues.py
parentede157331b4f9e550334900b3b4de1c8590688de (diff)
downloadcpython-git-5f841b553814969220b096a2b4f959b7f6fcbaf6.tar.gz
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
Diffstat (limited to 'Lib/asyncio/queues.py')
-rw-r--r--Lib/asyncio/queues.py22
1 files changed, 7 insertions, 15 deletions
diff --git a/Lib/asyncio/queues.py b/Lib/asyncio/queues.py
index 4fc681dde9..10e694f139 100644
--- a/Lib/asyncio/queues.py
+++ b/Lib/asyncio/queues.py
@@ -7,7 +7,6 @@ import heapq
from . import events
from . import locks
-from .coroutines import coroutine
class QueueEmpty(Exception):
@@ -28,7 +27,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
@@ -116,20 +115,17 @@ class Queue:
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
slot is available before adding item.
-
- This method is a coroutine.
"""
while self.full():
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():
@@ -151,19 +147,16 @@ class Queue:
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.
-
- This method is a coroutine.
"""
while self.empty():
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.
@@ -210,8 +203,7 @@ class Queue:
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
@@ -220,7 +212,7 @@ class Queue:
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):