Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Queue.get_nowait() and Queue.get() raise AssertionError when there are multiple tasks waiting for free slots. #265

@manipopopo

Description

@manipopopo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions