◐ Shell
clean mode source ↗

Message 64600 - Python tracker

Hmm, I think I know what happens. t_bootstrap() in threadmodule.c calls
the self.__bootstrap() method in the Thread object, and it is this
method which sets the __stopped flag at its end, which in turns wakes up
the join() method.

The problem is that at this point, t_bootstrap() still (rightly) holds a
reference to the Thread object, since it has a reference to its
__bootstrap() method which is still running. Depending on how the
operating system switches threads, this reference may or may not be
released when the join() method returns.

So I think it's the test that is flaky. Instead of calling the join()
method, it should wait for the OS-level thread to finish. Or it should
find another way of testing for the reference cycle.