Skip to content

Commit 63f23d5

Browse files
committed
gh-117683: Fix test_free_different_thread failures with GIL disabled
1 parent 6edde8a commit 63f23d5

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Lib/test/test_code.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
ctypes = None
142142
from test.support import (cpython_only,
143143
check_impl_detail, requires_debug_ranges,
144-
gc_collect)
144+
gc_collect, Py_GIL_DISABLED)
145145
from test.support.script_helper import assert_python_ok
146146
from test.support import threading_helper, import_helper
147147
from test.support.bytecode_helper import instructions_with_positions
@@ -865,7 +865,12 @@ def __init__(self, f, test):
865865
def run(self):
866866
del self.f
867867
gc_collect()
868-
self.test.assertEqual(LAST_FREED, 500)
868+
if Py_GIL_DISABLED:
869+
# gh-117683: The code object's destructor may still
870+
# be running concurrently in the main thread.
871+
self.test.assertIn(LAST_FREED, (None, 500))
872+
else:
873+
self.test.assertEqual(LAST_FREED, 500)
869874

870875
SetExtra(f.__code__, FREE_INDEX, ctypes.c_voidp(500))
871876
tt = ThreadTest(f, self)

0 commit comments

Comments
 (0)