diff --git a/Doc/library/concurrency.rst b/Doc/library/concurrency.rst index 18f9443cbfea20..bd554cbbe9a686 100644 --- a/Doc/library/concurrency.rst +++ b/Doc/library/concurrency.rst @@ -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 ` + * - 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 + :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::