[issue19466] Clear state of threads earlier in Python shutdown

Charles-François Natali report at bugs.python.org
Fri Dec 13 09:30:38 CET 2013


Charles-François Natali added the comment:

Hum...
Correct me if I'm wrong, but destroying the thread state of daemon threads
while they're running is really a bad idea in fact: for example, if
warnings are now emitted for unclosed file objects, this means that the
file object, and all associated buffers, are destroyed.
But even though the daemon thread doesn't hold the GIL, he might still be
using this object.

For example, if we have:
daemon thread:
readinto:
    release_gil
    read(fd, fileobj->buffer, fileobj->size)
    acquire_gil

and the main thread exits, then fileobj will be deallocated.

It's actually fairly easy to write a short crasher launching a deamon
thread reading from e.g. /dev/zero in loop, with the main thread exiting
right in the middle.

----------

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


More information about the Python-bugs-list mailing list