Marco Paolini added the comment:

> I don't understand how keeping a strong refrence would fix anything. You
> only provided one example (async-gc-bug.py) which uses Queue objects but
> keep weak references to them. Keeping strong references to tasks is not the
> right fix. You must keep strong references to queues. If a queue is
> destroyed, how can you put an item into it? Otherwise, the task will wait
> forever. Keeping a strong refrence to the task just hides the bug. Or I
> missed something.

The original asyncio-gc-issue.py wasn't written by me, and yes, as you say it 
does have the reference bug you describe. I argue that bug shouldn't cause 
tasks to die: it should rather limit (as gc proceeds) the number of queues 
available to the producer in the WeakSet() and leaving alive all consumer 
waiting on an unreachable queue.

Please look at my test2.py or even better test3.py for a simpler example.

Note that in my issue_22163_patch_0.diff I only keep strong refs to futures a 
task is waiting on. Just as asyncio is already doing with asyncio.sleep() 
coroutine.

> I dislike the idea of keeping strong references to tasks, it may create
> even more reference cycles. We already have too many cycles with exceptions
> stored in futures (in tasks).
We are also already keeping strong refs to futures like asyncio.sleep

I dislike the idea of randomly losing tasks.

I also dislike the idea of forcing the user to manage strong refs to its tasks. 
All 3rd party libraries will have to invent their own way and it will lead to 
even more leaks/cycles very hard to debug.

Not just exceptions: everytime a task is yielding on a future asyncio creates a 
reference cycle.

> The current unit test uses low level functions to remove a variable using a
> frame object. Can you provide an example which shows the bug without using
> low level functions?

My issue_22163_patch_0.diff only clears references by setting variables to 
`None`. No low level stuff needed.
 
My test2.py example script also doesn't use any low level stuff

I just uploaded test3.py with a simpler (and possibly more realistic) example.

----------
Added file: http://bugs.python.org/file36413/test3.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue21163>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to