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

The free-threaded GC only does full collections, so it uses a threshold that
is a maximum of a fixed value (default 2000) and proportional to the number of
live objects. If there were many live objects after the previous collection,
then the threshold may be larger than 10,000 causing
`test_indirect_calls_with_gc_disabled` to fail.

This manually sets the threshold to `(1000, 0, 0)` for the test. The `0`
disables the proportional scaling.
This commit is contained in:
Sam Gross 2024-03-13 09:27:36 -04:00 committed by GitHub
parent 186af3cf21
commit 8e2aab7ad5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View file

@ -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."""