Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Use threading instead of thread. Resolve _DummyThread bug. #333
The cause of the bug is best narrowed in comments by Richard Oudkerk and cooyeah. What happens is the following:
The threading API has a feature that you can call threading.currentThread() even from a thread not created by the threading API. What you get back is an instance of a "dummy thread", which supports a very limited subset of the Thread API, but is still useful for identifying the current thread.
threading._DummyThread is implemented as a subclass of Thread. Thread instances normally contain an internal callable (self.__block) that keeps reference to an OS-level lock allocated for the instance. Since the Thread methods that would end up calling self.__block are overridden by _DummyThread to not do that, _DummyThread's constructor releases the OS lock by deleting self.__block.
Because of a bug in threading._after_fork, the private __stop method gets called on all the registered threads, including the dummy threads. The correct patch is to change threading._after_fork to no longer do that, which is what the final patch in the issue does. (IMHO it would be even better to change _DummyThread to inherit from a thread base rather than from Thread, but that change would be backward-incompatible.)