File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,6 +10,40 @@ task to be executed (CPU bound vs IO bound) and preferred style of
1010development (event driven cooperative multitasking vs preemptive
1111multitasking). Here's an overview:
1212
13+ .. _concurrency-choosing :
14+
15+ .. list-table ::
16+ :header-rows: 1
17+ :widths: 40 30 30
18+
19+ * - What the program does
20+ - Default build
21+ - :term: `Free-threaded build <free-threaded build> `
22+ * - Calls blocking functions, such as file or database access
23+ - Threads
24+ - Threads
25+ * - Waits on many network connections, or needs cancellation and timeouts
26+ - :mod: `asyncio `
27+ - :mod: `asyncio `
28+ * - CPU-bound work in :term: `native code ` that releases the
29+ :term: `global interpreter lock `
30+ - Threads
31+ - Threads
32+ * - CPU-bound work in Python code
33+ - :mod: `multiprocessing ` or :mod: `concurrent.interpreters `
34+ - Threads
35+ * - Work that shares little data or needs isolation
36+ - :mod: `multiprocessing ` or :mod: `concurrent.interpreters `
37+ - :mod: `multiprocessing ` or :mod: `concurrent.interpreters `
38+
39+ In an :mod: `asyncio ` program, use :func: `asyncio.to_thread ` for the work the
40+ table assigns to threads. Calling a blocking function directly stalls the event
41+ loop, even if the function releases the :term: `global interpreter lock `.
42+
43+ The modules listed below provide these tools, along with lower-level building
44+ blocks such as :mod: `queue ` and :mod: `contextvars `. :mod: `asyncio ` is
45+ documented in :ref: `ipc `.
46+
1347
1448.. toctree ::
1549
You can’t perform that action at this time.
0 commit comments