Skip to content

Commit

Permalink
Fix intermittent failures for the `PyUnstable_Object_EnableDeferredRe…
Browse files Browse the repository at this point in the history
…fcount` tests (pythonGH-126849)

Hotfix for the PyUnstable_Object_EnableDeferredRefcount tests.
  • Loading branch information
ZeroIntensity authored and picnixz committed Nov 19, 2024
1 parent d98b5bd commit ae2e425
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions Lib/test/test_capi/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def test_ClearWeakRefsNoCallbacks_no_weakref_support(self):
_testcapi.pyobject_clear_weakrefs_no_callbacks(obj)


@threading_helper.requires_working_threading()
class EnableDeferredRefcountingTest(unittest.TestCase):
"""Test PyUnstable_Object_EnableDeferredRefcount"""
@support.requires_resource("cpu")
Expand All @@ -158,21 +159,13 @@ def silly_func(obj):

silly_list = [1, 2, 3]
threads = [
Thread(target=silly_func, args=(silly_list,)) for _ in range(5)
Thread(target=silly_func, args=(silly_list,)) for _ in range(4)
]

with threading_helper.catch_threading_exception() as cm:
for t in threads:
t.start()

with threading_helper.start_threads(threads):
for i in range(10):
silly_list.append(i)

for t in threads:
t.join()

self.assertIsNone(cm.exc_value)

if support.Py_GIL_DISABLED:
self.assertTrue(_testinternalcapi.has_deferred_refcount(silly_list))

Expand Down

0 comments on commit ae2e425

Please sign in to comment.