mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-131586: Avoid refcount contention in context managers (gh-131851)
This avoid reference count contention in the free threading build when calling special methods like `__enter__` and `__exit__`.
This commit is contained in:
parent
8dfa840773
commit
da53660f35
11 changed files with 247 additions and 207 deletions
|
@ -65,6 +65,19 @@ def object_lookup_special():
|
|||
for i in range(N):
|
||||
round(i / N)
|
||||
|
||||
class MyContextManager:
|
||||
def __enter__(self):
|
||||
pass
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
pass
|
||||
|
||||
@register_benchmark
|
||||
def context_manager():
|
||||
N = 1000 * WORK_SCALE
|
||||
for i in range(N):
|
||||
with MyContextManager():
|
||||
pass
|
||||
|
||||
@register_benchmark
|
||||
def mult_constant():
|
||||
x = 1.0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue