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
34 changes: 34 additions & 0 deletions Doc/library/concurrency.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,40 @@ task to be executed (CPU bound vs IO bound) and preferred style of
development (event driven cooperative multitasking vs preemptive
multitasking). Here's an overview:

.. _concurrency-choosing:

.. list-table::
:header-rows: 1
:widths: 40 30 30

* - What the program does
- Default build
- :term:`Free-threaded build <free-threaded build>`
* - Calls blocking functions, such as file or database access
- Threads
- Threads
* - Waits on many network connections, or needs cancellation and timeouts
- :mod:`asyncio`
- :mod:`asyncio`
* - CPU-bound work in :term:`native code` that releases the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add the term links here as well.

:term:`global interpreter lock`
- Threads
- Threads
* - CPU-bound work in Python code
- :mod:`multiprocessing` or :mod:`concurrent.interpreters`
- Threads
* - Work that shares little data or needs isolation
- :mod:`multiprocessing` or :mod:`concurrent.interpreters`
- :mod:`multiprocessing` or :mod:`concurrent.interpreters`

In an :mod:`asyncio` program, use :func:`asyncio.to_thread` for the work the
table assigns to threads. Calling a blocking function directly stalls the event
loop, even if the function releases the :term:`global interpreter lock`.

The modules listed below provide these tools, along with lower-level building
blocks such as :mod:`queue` and :mod:`contextvars`. :mod:`asyncio` is
documented in :ref:`ipc`.


.. toctree::

Expand Down
Loading