-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-120321: Lock gen_send #120327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-120321: Lock gen_send #120327
Conversation
What's the root cause of #120321? This feels like slapping a lock on something and hoping it works. |
The crash's root cause is here https://github.com/python/cpython/pull/120327/files#diff-2a0c449b68605ebd0872fd232e60ce7e838a77782a6d2e364764f99514fb508aR219 Those 3 lines can race and cause I locked the whole thing because TSAN is warning not just those few lines. It warns that the _PyFrame_StackPush and all the other stack accessor functions in there are racing as well. Though I don't think that results in a crash. |
What about all the other places that I suspect that this doesn't crash only because specialization is turned off for free-threading: def gen():
while True:
yield
def my_next(it):
for val in it:
return value
raise StopIteration
it = gen()
with concurrent.futures.ThreadPoolExecutor() as executor:
while True:
_ = executor.submit(lambda: my_next(it)) |
Yeah the entire gen_send has multiple races in multiple places. Likewise for the specializing interpreter. So the entire thing needs to be locked (what the GIL does at the moment). |
Pushing and popping generator frames needs to be locked. The best way to do that would be to move popping and pushing into its own helper function. |
I agree that pushing and popping frames need fixing, but |
OOI, what are the other crashes? |
A selection of them after I've locked just the frame pushing
|
I wonder if we really only need the locks up to the transition to I think other than the asserts that only leaves |
What's the status of this PR? It now has multiple merge conflicts. |
Adds per-object lock for gen_send to fix crashes.