[issue26617] Assertion failed in gc with __del__ and weakref

Yang Ke report at bugs.python.org
Wed Mar 23 02:49:42 EDT 2016


Yang Ke added the comment:

The crash may be raised on both Windows OS and Linux. We got crashed under Ubuntu 14.04, while a similar issue was found https://bugs.python.org/issue23187#msg238139 last year under Windows OS.

We actually raise such bug working on a program with asyncio and multithread(use asyncio.BaseEventLoop.run_in_executor with its default threadpool).
The asyncio.Task class creates a weakref.WeakSet(https://hg.python.org/cpython/file/3.5/Lib/asyncio/tasks.py#l38) containing alive tasks. WeakSet is implemented as a list containing weakref.ref with CALLBACK function(https://hg.python.org/cpython/file/3.5/Lib/_weakrefset.py#l84). And that may lead to the situation described in sample crash code:
Once a asyncio.Task.__del__ function is called, and callback of the weakref is called, then the interpreter switches to other thread, which may trigger gc.collect(the thread allocate a huge number of objects, for example), and leaves the task object in gc_list with refcount==0.

----------
nosy: +Yang Ke -Guo. Jiahua

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26617>
_______________________________________


More information about the Python-bugs-list mailing list