The following code produce an AssertionError:
import asyncio
queue = asyncio.Queue(2)
async def putter(item):
await queue.put(item)
async def getter():
await asyncio.sleep(1)
num = queue.qsize()
try:
for _ in range(num):
item = queue.get_nowait()
except AssertionError as e:
print(e)
asyncio.ensure_future(putter(0))
asyncio.ensure_future(putter(1))
asyncio.ensure_future(putter(2))
asyncio.ensure_future(putter(3))
asyncio.get_event_loop().run_until_complete(getter())
When getter called get_nowait() (or await queue.get()), one pending putter would be scheduled to put an item in the next step of the event loop. When get_nowait() (or await queue.get()) was called for the second time, the queue was not full and the assertion in Queue.get_nowait (and Queue.get)
assert self.full(), 'queue not full, why are putters waiting?'
failed.
It seems 1dd213e causes the problem.