gh-117657: Fix race involving immortalizing objects (#119927)

The free-threaded build currently immortalizes objects that use deferred
reference counting (see gh-117783). This typically happens once the
first non-main thread is created, but the behavior can be suppressed for
tests, in subinterpreters, or during a compile() call.

This fixes a race condition involving the tracking of whether the
behavior is suppressed.
This commit is contained in:
Sam Gross 2024-06-03 16:58:41 -04:00 committed by GitHub
parent b8fde5db86
commit 47fb4327b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 30 additions and 44 deletions

View file

@ -529,11 +529,11 @@ def suppress_immortalization(suppress=True):
yield
return
old_values = _testinternalcapi.set_immortalize_deferred(False)
_testinternalcapi.suppress_immortalization(True)
try:
yield
finally:
_testinternalcapi.set_immortalize_deferred(*old_values)
_testinternalcapi.suppress_immortalization(False)
def skip_if_suppress_immortalization():
try: