Closed colesbury closed 2 weeks ago
I'm able to reproduce this locally on Linux with a few modifications:
First, apply https://gist.github.com/colesbury/f8ba31699eb6fcc79a29a2dd4e41e817 to enable the test and run it in a loop.
Then run multiple test instances in parallel on a single CPU:
taskset -c 0 ./python -m test -j 8 test_multiprocessing_spawn.test_threads -m test.test_multiprocessing_spawn.test_threads.WithThreadsTestPool.test_release_task_refs test_multiprocessing_spawn.test_threads -m test.test_multiprocessing_spawn.test_threads.WithThreadsTestPool.test_release_task_refs test_multiprocessing_spawn.test_threads -m test.test_multiprocessing_spawn.test_threads.WithThreadsTestPool.test_release_task_refs test_multiprocessing_spawn.test_threads -m test.test_multiprocessing_spawn.test_threads.WithThreadsTestPool.test_release_task_refs test_multiprocessing_spawn.test_threads -m test.test_multiprocessing_spawn.test_threads.WithThreadsTestPool.test_release_task_refs test_multiprocessing_spawn.test_threads -m test.test_multiprocessing_spawn.test_threads.WithThreadsTestPool.test_release_task_refs test_multiprocessing_spawn.test_threads -m test.test_multiprocessing_spawn.test_threads.WithThreadsTestPool.test_release_task_refs test_multiprocessing_spawn.test_threads -m test.test_multiprocessing_spawn.test_threads.WithThreadsTestPool.test_release_task_refs
The fix is to move the time.sleep(DELTA)
before the gc.collect()
:
The time.sleep()
is because the worker processes hold onto the result briefly after it's returned to the main thread. In the free-threaded build, we want the gc.collect()
to happen after the workers no longer reference the the CountedObject()
values because of the some objects passed across threads have their destructors delayed.
The test is fixed now and re-enabled in the free-threaded build.
This might be a free-threading related bug or possibly a flaky test. We should investigate and try to figure out the root cause.
Originally reported by hugovk in https://github.com/python/cpython/issues/118331#issuecomment-208372155 (https://github.com/python/cpython/actions/runs/8884999534/attempts/1).
Linked PRs