This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients giampaolo.rodola, gvanrossum, pitrou, richard.kiss, vstinner, yselivanov
Date 2014-06-19.14:48:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1403189318.53.0.786212703865.issue21163@psf.upfronthosting.co.za>
In-reply-to
Content
Ok, I agree that this issue is very tricky :-)

The first problem in asyncio-gc-issue.py is that the producer keeps *weak* references to Queue object, so the Queue objects are quickly destroyed, especially if gc.collect() is called explicitly.

When "yield from queue.get()" is used in a task, the task is paused. The queue creates a Future object and the task registers its _wakeup() method into the Future object.

When the queue object is destroyed, the internal future object (used by the get() method) is destroyed too. The last reference to the task was in this future object. As a consequence, the task is also destroyed.

While there is a bug in asyncio-gc-issue.py, it's very tricky to understand it and I think that asyncio should help developers to detect such bugs.


I propose attached patch which emits a warning if a task is destroyed whereas it is not done (its status is still PENDING). I wrote a unit test which is much simpler than asyncio-gc-issue.py. Read the test to understand the issue. I added many comments to explain the state.

--

My patch was written for Python 3.4+: it adds a destructor to the Task class, and we cannot add a destructor in Future objects because these objects are likely to be part of reference cycles. See the following issue which proposes a fix:
https://code.google.com/p/tulip/issues/detail?id=155

Using this fix for reference cycle, it may be possible to emit also the log in Tulip (Python 3.3).
History
Date User Action Args
2014-06-19 14:48:38vstinnersetrecipients: + vstinner, gvanrossum, pitrou, giampaolo.rodola, yselivanov, richard.kiss
2014-06-19 14:48:38vstinnersetmessageid: <1403189318.53.0.786212703865.issue21163@psf.upfronthosting.co.za>
2014-06-19 14:48:38vstinnerlinkissue21163 messages
2014-06-19 14:48:38vstinnercreate