This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author chris.jerdonek
Recipients brett.cannon, chris.jerdonek, ezio.melotti, zach.ware
Date 2013-01-26.17:22:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Okay, I think I understand the issue better now.  The threading._dangling warning happens because when leaving the saved_test_environment context manager in regrtest:

the context manager finds threads still in threading._dangling that weren't there at the beginning.  I think the threads are still in there because the "tests" variable in the code linked to above is holding references to those threads (which isn't surprising given what tests).  So this is preventing the threads (which are in a WeakSet) from being garbage collected.

On my machine, severing those references before leaving the context manager solves the problem.  You can do this by adding "test = 0" after the test_runner() line, or defining "tests" inside an inner function as follows:

if test_runner is None:
    def test_runner():
        tests = unittest.TestLoader().loadTestsFromModule(the_module)

To be completely sure, we may also need to do something to ensure that the threads are garbage collected before leaving the context manager.  Currently, an explicit call to support.gc_collect() happens in threading_cleanup() (which is in turn called by reap_threads(), etc):

But I'm not sure if that's late enough in the process to guarantee garbage collection of those threads with the test_runner() change above (since the tests list might still be defined).
Date User Action Args
2013-01-26 17:22:48chris.jerdoneksetrecipients: + chris.jerdonek, brett.cannon, ezio.melotti, zach.ware
2013-01-26 17:22:48chris.jerdoneksetmessageid: <>
2013-01-26 17:22:48chris.jerdoneklinkissue16968 messages
2013-01-26 17:22:48chris.jerdonekcreate