From 47754de16860745abe65fe75989157d4bce3a893 Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Mon, 30 Nov 2026 12:11:28 -0700 Subject: [PATCH 1/2] gh-145912: Clarify the note about the GIL in the asyncio.to_thread() docs --- Doc/library/asyncio-task.rst | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst index bc79927b9856270..dc885585f89596d 100644 --- a/Doc/library/asyncio-task.rst +++ b/Doc/library/asyncio-task.rst @@ -1097,10 +1097,13 @@ Running in threads .. note:: - Due to the :term:`GIL`, ``asyncio.to_thread()`` can typically only be used - to make IO-bound functions non-blocking. However, for extension modules - that release the GIL or alternative Python implementations that don't - have one, ``asyncio.to_thread()`` can also be used for CPU-bound functions. + ``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. In the :term:`free-threaded build` there + is no GIL, so the two threads do not have to take turns. .. versionadded:: 3.9 From 92e9309439819e3b624ab30942ce2a8f5a0db0ba Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Mon, 30 Nov 2026 12:47:37 -0700 Subject: [PATCH 2/2] tweak wording --- Doc/library/asyncio-task.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst index dc885585f89596d..beb66fb37a0fd0a 100644 --- a/Doc/library/asyncio-task.rst +++ b/Doc/library/asyncio-task.rst @@ -1102,8 +1102,10 @@ Running in 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. In the :term:`free-threaded build` there - is no GIL, so the two threads do not have to take turns. + :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 ` with the event loop. .. versionadded:: 3.9