gh-138199: Address potential confusion re: threading #138200
Open
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.
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:
!asyncio
automatically 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:
!asyncio
together, 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/