-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-109955 : Update state transition comments for asyncio.Task #109910
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
Conversation
093b5c5
to
3b9b4cf
Compare
Lib/asyncio/tasks.py
Outdated
# The transition from 2a to 2b happens when __wakeup() is executed, | ||
# scheduling __step() to be called, leaving _fut_waiter in place. |
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.
This confuses me. Once __wakeup()
executes, it proceeds without waiting to call __step()
-- there's no scheduling involved that I can see in the source code (unless the .c extension is different). The call to future.result()
immediately produces a value or raises -- it doesn't block (there's no await
there). I do think it is possible to enter step 2b without going through 2a when __step()
is scheduled directly by __init__()
. So maybe it's clearer to say that we go through either 2a or 2b?
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 may have got my wires crossed here, because it is all confusing. Initially, I thought __wakeup() was called directly (futures just calling registered callbacks) and _wakeup scheduling __step,.. But then it turns out that futures schedule their callbacks... I'll have another look.
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.
Yes, you were right. So, there is no 2a or2b anymore just 2.
The main point I'm trying to get across here is that there can be a _fut_waiter
present in a done
state, i.e. the
mere presence of a _fut_waiter
does not indicate that the Task is still blocked. I hope I'm not making this sound more complicated than it is.
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.
the mere presence of a
_fut_waiter
does not indicate that the Task is still blocked
Yes, that's crucial information.
Co-authored-by: Adam Turner <[email protected]>
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'll merge it now. Thanks!
Thanks @kristjanvalur for the PR, and @gvanrossum for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
…ythonGH-109910) (cherry picked from commit 45cf5b0) Co-authored-by: Kristján Valur Jónsson <[email protected]> Co-authored-by: Adam Turner <[email protected]>
GH-109992 is a backport of this pull request to the 3.12 branch. |
GH-109993 is a backport of this pull request to the 3.11 branch. |
…ythonGH-109910) (cherry picked from commit 45cf5b0) Co-authored-by: Kristján Valur Jónsson <[email protected]> Co-authored-by: Adam Turner <[email protected]>
…ython#109910) Co-authored-by: Adam Turner <[email protected]>
…H-109910) (#109993) gh-109955 : Update state transition comments for asyncio.Task (GH-109910) (cherry picked from commit 45cf5b0) Co-authored-by: Kristján Valur Jónsson <[email protected]> Co-authored-by: Adam Turner <[email protected]>
…H-109910) (#109992) gh-109955 : Update state transition comments for asyncio.Task (GH-109910) (cherry picked from commit 45cf5b0) Co-authored-by: Kristján Valur Jónsson <[email protected]> Co-authored-by: Adam Turner <[email protected]>
…ython#109910) Co-authored-by: Adam Turner <[email protected]>
The in-line comments for the state transition of asyncio.Task objects has been out of date
for quite some time.
_fut_waiter
persist in a done state on the Task between becoming done and until__step()
is executed.__wakeup()
is scheduled, followed by 2b when__step()
is scheduled._step()
and_wakeup()
have been__step()
and__wakeup()
for quite some time.This PR attempts to rectify the situation.
asyncio.tasks
are out of date #109955