The test attempts to ensure that the executor doesn't hold on to the result object, but the executor necessarily holds onto it for a brief period from when it sets the result in in the future until the variable goes out of scope.
We should use support.sleeping_retry to check if the weakref eventually (ideally quickly) becomes dead.
======================================================================
FAIL: test_free_reference (test.test_concurrent_futures.test_thread_pool.ThreadPoolExecutorTest.test_free_reference)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/ec2-user/buildbot/buildarea/3.x.itamaro-macos-arm64-aws.macos-with-brew.refleak.nogil/build/Lib/test/test_concurrent_futures/executor.py", line 132, in test_free_reference
self.assertIsNone(wr())
~~~~~~~~~~~~~~~~~^^^^^^
AssertionError: <test.test_concurrent_futures.executor.MyObject object at 0x200041b0100> is not None
----------------------------------------------------------------------
Activity
colesbury commented on Mar 7, 2025
You can more easily reproduce this failure by adding a time.sleep():
pythongh-130957: Use sleeping_retry in test_free_reference
gh-130957: Use `sleeping_retry` in `test_free_reference` (#130958)
pythongh-130957: Use `sleeping_retry` in `test_free_reference` (pytho…
pythongh-130957: Use `sleeping_retry` in `test_free_reference` (pytho…
[3.12] gh-130957: Use `sleeping_retry` in `test_free_reference` (GH-1…
[3.13] gh-130957: Use `sleeping_retry` in `test_free_reference` (GH-1…