New submission from A. Jesse Jiryu Davis: In threading.Thread.__bootstrap_inner(), the thread sets self.__started before adding itself to the _active collection. If a different thread forks between these two operations, we're left with a thread that believes it's alive although it isn't. _after_fork() doesn't call __stop() on this thread because the thread isn't in _active.
In the attached patch, Thread adds itself to _active before setting self.__started. This way, if it's interrupted by a fork, it may end up stopped without being started, rather than the reverse. In this case isAlive() correctly returns False. One concern about the patch: my new test in test_threading.py only reveals the bug in Python 2.7.5 very occasionally. I don't know how to force the test to fail more frequently. Looking at the threading.py on the 3.3 branch, it appears to have the same bug, but I can't reproduce it there, only on the 2.7 branch. ---------- components: Library (Lib) files: fix_is_alive_and_fork.patch keywords: patch messages: 192780 nosy: emptysquare priority: normal severity: normal status: open title: Thread.isAlive() sometimes True after fork versions: Python 2.7 Added file: http://bugs.python.org/file30880/fix_is_alive_and_fork.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue18418> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com