diff options
author | Sam Gross <colesbury@gmail.com> | 2024-04-29 18:36:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-29 18:36:02 (GMT) |
commit | 7ccacb220d99662b626c8bc63b00a27eaf604f0c (patch) | |
tree | 231cb901ee62e523be237392b0f2b966aa8be128 /Lib/test/support | |
parent | 8d4b756fd31d4d91b55105b1241561e92cc571a3 (diff) | |
download | cpython-7ccacb220d99662b626c8bc63b00a27eaf604f0c.zip cpython-7ccacb220d99662b626c8bc63b00a27eaf604f0c.tar.gz cpython-7ccacb220d99662b626c8bc63b00a27eaf604f0c.tar.bz2 |
gh-117783: Immortalize objects that use deferred reference counting (#118112)
Deferred reference counting is not fully implemented yet. As a temporary
measure, we immortalize objects that would use deferred reference
counting to avoid multi-threaded scaling bottlenecks.
This is only performed in the free-threaded build once the first
non-main thread is started. Additionally, some tests, including refleak
tests, suppress this behavior.
Diffstat (limited to 'Lib/test/support')
-rw-r--r-- | Lib/test/support/__init__.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 70d2610..15f6543 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -516,6 +516,25 @@ def has_no_debug_ranges(): def requires_debug_ranges(reason='requires co_positions / debug_ranges'): return unittest.skipIf(has_no_debug_ranges(), reason) +@contextlib.contextmanager +def suppress_immortalization(suppress=True): + """Suppress immortalization of deferred objects.""" + try: + import _testinternalcapi + except ImportError: + yield + return + + if not suppress: + yield + return + + old_values = _testinternalcapi.set_immortalize_deferred(False) + try: + yield + finally: + _testinternalcapi.set_immortalize_deferred(*old_values) + MS_WINDOWS = (sys.platform == 'win32') # Is not actually used in tests, but is kept for compatibility. |