Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-116604: Fix test_gc on free-threaded build #116662

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,16 @@ def disable_gc():
if have_gc:
gc.enable()

@contextlib.contextmanager
def gc_threshold(*args):
import gc
old_threshold = gc.get_threshold()
gc.set_threshold(*args)
try:
yield
finally:
gc.set_threshold(*old_threshold)


def python_is_optimized():
"""Find if Python was built with optimizations."""
Expand Down
4 changes: 3 additions & 1 deletion Lib/test/test_gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from test.support.import_helper import import_module
from test.support.os_helper import temp_dir, TESTFN, unlink
from test.support.script_helper import assert_python_ok, make_script
from test.support import threading_helper
from test.support import threading_helper, gc_threshold

import gc
import sys
Expand Down Expand Up @@ -1330,6 +1330,7 @@ def callback(ignored):
# with an empty __dict__.
self.assertEqual(x, None)

@gc_threshold(1000, 0, 0)
def test_bug1055820d(self):
# Corresponds to temp2d.py in the bug report. This is very much like
# test_bug1055820c, but uses a __del__ method instead of a weakref
Expand Down Expand Up @@ -1397,6 +1398,7 @@ def __del__(self):
# empty __dict__.
self.assertEqual(x, None)

@gc_threshold(1000, 0, 0)
def test_indirect_calls_with_gc_disabled(self):
junk = []
i = 0
Expand Down
Loading