Message180689
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:
http://hg.python.org/cpython/file/fcdb35b114ab/Lib/test/regrtest.py#l1271
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 test_concurrent_futures.py 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)
support.run_unittest(tests)
test_runner()
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):
http://hg.python.org/cpython/file/fcdb35b114ab/Lib/test/support.py#l1665
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:48 | chris.jerdonek | set | recipients:
+ chris.jerdonek, brett.cannon, ezio.melotti, zach.ware |
2013-01-26 17:22:48 | chris.jerdonek | set | messageid: <1359220968.86.0.354478530217.issue16968@psf.upfronthosting.co.za> |
2013-01-26 17:22:48 | chris.jerdonek | link | issue16968 messages |
2013-01-26 17:22:48 | chris.jerdonek | create | |
|