aio-libs / janus

Thread-safe asyncio-aware queue for Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

join() calls should raise RuntimeError while the queue is closing or closed.

linw1995 opened this issue · comments

Recently discover that it can call q.join() on a closed queue. And I notice the q.join() will block forever even after the queue being closed.

It is better that it should check parent queue is closing or not, while q.join() calling or to be called.

The q.join() calls should raise RuntimeError, when q.join() calls on a closed queue or when closing a queue while q.join() is calling.

import janus


async def join_after_closing():
    q = jauns.Queue()
    await q.async_q.put("boo")
    q.close()
    await q.async_q.join()  # blocks forever


async def close_after_join():
    q = jauns.Queue()
    await q.async_q.put("boo")
    task = janus.ensure_future(q.async_q.join())
    await asyncio.sleep(1) # ensure the task is blocking
    q.close()
    await task  # blocks forever too

Agree. Would you provide a pull request with the fix?

Agree. Would you provide a pull request with the fix?

@asvetlov Yes. I create a pull request to fix this. #295

Fixed by #295