[docs] [issue34172] multiprocessing.Pool and ThreadPool leak resources after being deleted

tzickel report at bugs.python.org
Sat Aug 4 09:10:34 EDT 2018

tzickel <icebreak at yahoo.com> added the comment:

It actually makes tons of sense that while the thread is running, that the object representing it is alive. After the thread finishes its work, the object dies.

>>> import time, threading, weakref, gc
>>> t = threading.Thread(target=time.sleep, args=(10,))
>>> wr = weakref.ref(t)
>>> t.start()
>>> del t
>>> gc.collect()
>>> wr()
<Thread(Thread-1, started 139937234327296)>
Wait 10 seconds...
>>> gc.collect()
>>> wr()

The thread is gone (which doesn't happen with the pool).

Anyhow, I've submitted a patch to fix the bug that was introduced 9 years ago on GH, feel free to check it.


Python tracker <report at bugs.python.org>

More information about the docs mailing list