tornadoweb / tornadoweb/tornado

tornado.queues consumers are difficult to stop cleanly

Open
#2,356 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

queues
Dominant language
Python
Stars
22.2k
Forks
5.6k
Avg merge
3h 42m
Merged PRs (30d)
16

Description

While using tornado 5.0.2, the following code will report
ERROR:asyncio:Task was destroyed but it is pending! task: <Task pending coro=<consumer() running at a.py:18> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x10eb7a6a8>()]> cb=[IOLoop.add_future.<locals>.<lambda>() at /usr/local/lib/python3.6/site-packages/tornado/ioloop.py:720]>

this code is copied from http://www.tornadoweb.org/en/stable/queues.html

from tornado import gen
from tornado.ioloop import IOLoop
from tornado.queues import Queue

q = Queue(maxsize=2)

async def consumer():
    async for item in q:
        try:
            print('Doing work on %s' % item)
        finally:
            q.task_done()


async def producer():
    for item in range(1):
        await q.put(item)
        print('Put %s' % item)


async def main():
    # Start consumer without waiting (since it never finishes).
    IOLoop.current().spawn_callback(consumer)
    await producer()     # Wait for producer to put all tasks.
    await q.join()       # Wait for consumer to finish all tasks.
    print('Done')

IOLoop.current().run_sync(main)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reproducer from the issue with Tornado 5.0.2 and inspect the tornado.queues consumer behavior around async iteration and shutdown. Done means the example can stop the consumer cleanly after q.join() without reporting a pending destroyed task.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.