gh-127020: Make PyCode_GetCode thread-safe for free threading#127043
Merged
colesbury merged 1 commit intopython:mainfrom Nov 21, 2024
Merged
gh-127020: Make PyCode_GetCode thread-safe for free threading#127043colesbury merged 1 commit intopython:mainfrom
PyCode_GetCode thread-safe for free threading#127043colesbury merged 1 commit intopython:mainfrom
Conversation
Some fields in PyCodeObject are lazily initialized. Use atomics and critical sections to make their initializations and accesses thread-safe.
mpage
approved these changes
Nov 20, 2024
Contributor
|
Hi @colesbury , Lysandros pointed me out to your PR fixing a bug in FT mode. import concurrent.futures
import threading
import inspect
def decorator(f):
# Introspect the callable for optional features.
sig = inspect.signature(f)
for param in sig.parameters.values():
pass
def emit_call_op(*call_args):
pass
wrapped = emit_call_op
return wrapped
def test_dialects_vector_repro_3():
num_workers = 6
num_runs = 10
barrier = threading.Barrier(num_workers)
def closure():
barrier.wait()
for _ in range(num_runs):
@decorator
def print_vector(arg):
return 0
barrier.wait()
with concurrent.futures.ThreadPoolExecutor(
max_workers=num_workers
) as executor:
futures = []
for _ in range(num_workers):
futures.append(executor.submit(closure))
# We should call future.result() to re-raise an exception if test has
# failed
assert len(list(f.result() for f in futures)) == num_workers
if __name__ == "__main__":
test_dialects_vector_repro_3()Outputs (cpython 3.13 built with TSAN): or Can you please check and run it in your PR and see if this is also fixed? Thanks a lot! |
Contributor
Author
|
@vfdev-5, I verified that it fixed your repro as well. |
|
Thanks @colesbury for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Nov 21, 2024
…pythonGH-127043) Some fields in PyCodeObject are lazily initialized. Use atomics and critical sections to make their initializations and accesses thread-safe. (cherry picked from commit 3926842) Co-authored-by: Sam Gross <colesbury@gmail.com>
|
GH-127107 is a backport of this pull request to the 3.13 branch. |
ebonnal
pushed a commit
to ebonnal/cpython
that referenced
this pull request
Jan 12, 2025
…python#127043) Some fields in PyCodeObject are lazily initialized. Use atomics and critical sections to make their initializations and accesses thread-safe.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some fields in PyCodeObject are lazily initialized. Use atomics and critical sections to make their initializations and accesses thread-safe.
PyCode_GetCodeis not thread-safe and causes assertion fail with Python 3.13td #127020