mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-123923: Defer refcounting for f_executable
in _PyInterpreterFrame
(#123924)
Use a `_PyStackRef` and defer the reference to `f_executable` when possible. This avoids some reference count contention in the common case of executing the same code object from multiple threads concurrently in the free-threaded build.
This commit is contained in:
parent
4ed7d1d6ac
commit
b2afe2aae4
18 changed files with 177 additions and 99 deletions
|
@ -6,6 +6,7 @@ import doctest
|
|||
import unittest
|
||||
import weakref
|
||||
import inspect
|
||||
import textwrap
|
||||
import types
|
||||
|
||||
from test import support
|
||||
|
@ -112,6 +113,27 @@ class FinalizationTest(unittest.TestCase):
|
|||
gen.send(2)
|
||||
self.assertEqual(cm.exception.value, 2)
|
||||
|
||||
def test_generator_resurrect(self):
|
||||
# Test that a resurrected generator still has a valid gi_code
|
||||
resurrected = []
|
||||
|
||||
# Resurrect a generator in a finalizer
|
||||
exec(textwrap.dedent("""
|
||||
def gen():
|
||||
try:
|
||||
yield
|
||||
except:
|
||||
resurrected.append(g)
|
||||
|
||||
g = gen()
|
||||
next(g)
|
||||
"""), {"resurrected": resurrected})
|
||||
|
||||
support.gc_collect()
|
||||
|
||||
self.assertEqual(len(resurrected), 1)
|
||||
self.assertIsInstance(resurrected[0].gi_code, types.CodeType)
|
||||
|
||||
|
||||
class GeneratorTest(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue