Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Doc/library/asyncio-task.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1097,10 +1097,15 @@ 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. 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.

.. versionadded:: 3.9

Expand Down
Loading