-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
gh-138199: Address potential confusion re: threading #138200
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-138199: Address potential confusion re: threading #138200
Conversation
|
@ZeroIntensity, I think you may like the proposed changes. It removes any mention of threading and I think improves clarity. If you have the time, I would appreciate a review :) |
ZeroIntensity
left a comment
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'm fine with this wording, but I think the final decision should be up to Kumar.
|
Ok, I'm going to merge this one. Kumar, if you have any strong objections to the wording, please feel free to send a revert or an update. |
|
Thanks @anordin95 for the PR, and @ZeroIntensity for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
|
Sorry, @anordin95 and @ZeroIntensity, I could not cleanly backport this to |
|
Sorry, @anordin95 and @ZeroIntensity, I could not cleanly backport this to |
|
@anordin95 Would you like to try handling the backports? |
|
GH-141928 is a backport of this pull request to the 3.14 branch. |
…he `asyncio` HOWTO (pythonGH-138200) (cherry picked from commit a4f4225)
|
GH-141929 is a backport of this pull request to the 3.13 branch. |
|
@ZeroIntensity - Mhm 👍 3.14: #141928 3.13: #141929 |
…he `asyncio` HOWTO (pythonGH-138200)
…he `asyncio` HOWTO (pythonGH-138200)
Right now, I think the article creates a logical gap that has the potential to confuse readers.
The "in each thread" part implies there can be multiple event loops (via multithreading) in the same memory space. It's quite natural to then wonder how tasks will be associated with event loops when there are multiple event loops to choose from. And how you, the user, could manage which loop a task is assigned to. I see that as an easy way for the reader to be left in the dark, wondering.
I see two potential solutions. One is clarifying how tasks and event loops are paired in a multithreaded environment. The other, not mentioning threads at all. I don't feel that strongly either way. However, I do feel strongly that if we mention threads we need to explain how threads and multiple event loops interact.
Approach 1
:mod:
!asyncioautomatically associates tasks with the event loop for you.Typically there's only one event loop, so that's quite straightforward.
It's uncommon, but some applications use multithreading and :mod:
!asynciotogether, where there's one event loop per thread, stored in thread-local
storage.
Approach 2
No mention of threads. See the suggested changes in this PR.
📚 Documentation preview 📚: https://cpython-previews--138200.org.readthedocs.build/