gh-138199: Address potential confusion re: threading #138200
Open
+5
−3
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 "per 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 personally lean towards mentioning threading and how event loops are paired with tasks. It is a detail the reader likely won't immediately need, but that's also not the purpose of a HOWTO/explainer. And I think it's a somewhat simple, interesting and powerful solution.
Approach 1
My suggested phrasing to clarify this is in the PR.
Approach 2
Instead of the proposed changes, remove any references to threads or the idea of multiple event loops. One possible approach would be replacing the relevant paragraph with only this:
":mod:
!asyncio
automatically associates tasks with the event loop for you.".📚 Documentation preview 📚: https://cpython-previews--138200.org.readthedocs.build/