Repository navigation
Conversation
ngoldbaum
requested review from
1st1,
asvetlov and
kumaraditya303
as code owners
November 30, 2026 19:39
18 of 49 tasks
Documentation build overview
|
Comment on lines
+1100
to
+1108
| ``asyncio.to_thread()`` lets the event loop keep running while *func* | ||
| runs in another thread. With the :term:`GIL` enabled, the two threads | ||
| take turns running Python code, so a CPU-bound function slows the event | ||
| loop down. The event loop is not slowed down while the function is in a | ||
| call that releases the GIL, which long-running calls into | ||
| :term:`native code` often do. With the GIL disabled on the | ||
| :term:`free-threaded build`, the two threads do not have to take turns, | ||
| and several CPU-bound functions can make progress in | ||
| :term:`parallel <parallelism>` with the event loop. |
Member
There was a problem hiding this comment.
We could also mention that setting the loop's default executor to an InterpreterPoolExecutor will also bypass the GIL 😄
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This note dates from when
asyncio.to_thread()was added in 3.9 (GH-20143), before the free-threaded build existed. Its current content is confusing now that the free-threaded build exists.The new wording explains that with the GIL enabled, a CPU-bound function in a thread slows the event loop down but does not block it. It also mentions the free-threaded build, where two threads don't have to take turns on a CPU-bound task.
Also see #162886, which this conflicts with. I'll handle dealing with the conflicts.