You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
WithThreadsTestPool.test_release_task_refs: flaky test or possible free-threading bug #118413
This might be a free-threading related bug or possibly a flaky test. We should investigate and try to figure out the root cause.
======================================================================
FAIL: test_release_task_refs (test.test_multiprocessing_spawn.test_threads.WithThreadsTestPool.test_release_task_refs)
----------------------------------------------------------------------
Traceback (most recent call last):
File "D:\a\cpython\cpython\Lib\test\_test_multiprocessing.py", line 2817, in test_release_task_refs
self.assertEqual(set(wr() for wr in refs), {None})
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Items in the first set but not the second:
<test._test_multiprocessing.CountedObject object at 0x03E7CA50>
changed the title [-]`WithThreadsTestPool.test_release_task_refs `: AssertionError: Items in the first set but not the second[/-][+]`WithThreadsTestPool.test_release_task_refs`: flaky test or possible free-threading bug[/+]on Apr 29, 2024
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.
Activity
[-]`WithThreadsTestPool.test_release_task_refs `: AssertionError: Items in the first set but not the second[/-][+]`WithThreadsTestPool.test_release_task_refs`: flaky test or possible free-threading bug[/+]pythongh-118413: Temporarily skip `test_release_task_refs` in free-th…
gh-118413: Temporarily skip `test_release_task_refs` in free-threaded…
colesbury commentedon May 1, 2024
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:
colesbury commentedon May 1, 2024
The fix is to move the
time.sleep(DELTA)before thegc.collect():cpython/Lib/test/_test_multiprocessing.py
Lines 2816 to 2817 in c408c36
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 thegc.collect()to happen after the workers no longer reference the theCountedObject()values because of the some objects passed across threads have their destructors delayed.pythongh-118413: Fix test_release_task_refs on free-threaded build
gh-118413: Fix test_release_task_refs on free-threaded build (#118494)
colesbury commentedon May 2, 2024
The test is fixed now and re-enabled in the free-threaded build.
pythongh-118413: Temporarily skip `test_release_task_refs` in free-th…
pythongh-118413: Fix test_release_task_refs on free-threaded build (p…