-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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-120974: Make asyncio swap_current_task
safe in free-threaded build
#122317
gh-120974: Make asyncio swap_current_task
safe in free-threaded build
#122317
Conversation
…ed build Use a critical section around the modifications to `current_tasks`.
!buildbot nogil refleaks |
🤖 New build scheduled with the buildbot fleet by @colesbury for commit 846f6f8 🤖 The command will test the builders whose names match following regular expression: The builders matched are:
|
Modules/_asynciomodule.c
Outdated
Py_hash_t hash, PyObject *task) | ||
{ | ||
PyObject *prev_task; | ||
if (_PyDict_GetItemRef_KnownHash(current_tasks, loop, hash, &prev_task) < 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also use a lock held
variant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it makes much of a difference, but we can. I'll add _PyDict_GetItemRef_KnownHash_LockHeld
.
The lock held
variants are important for the SetItem
calls so that we don't try to re-lock the dict. But not so much for the GetItem
calls, because those have fast paths that do not lock the dict.
Thanks @colesbury for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
…ed build (pythonGH-122317) * pythongh-120974: Make asyncio `swap_current_task` safe in free-threaded build (cherry picked from commit b5e6fb3) Co-authored-by: Sam Gross <colesbury@gmail.com>
GH-122612 is a backport of this pull request to the 3.13 branch. |
|
…ed build (python#122317) * pythongh-120974: Make asyncio `swap_current_task` safe in free-threaded build
…ed build (python#122317) * pythongh-120974: Make asyncio `swap_current_task` safe in free-threaded build
Use a critical section around the modifications to
current_tasks
so that the swapping is atomic.asyncio
thread-safety issues in the free-threaded build #120974