Skip to content

Commit 70986a0

Browse files
committed
Add section
1 parent 39cad63 commit 70986a0

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

Doc/library/threading.rst

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,6 @@ parallel, sharing memory space. Threads are particularly useful when tasks are
5757
I/O-bound, such as file operations or making network requests,
5858
where much of the time is spent waiting for external resources.
5959

60-
Unlike the :mod:`multiprocessing` module, which uses separate processes to
61-
bypass the :term:`Global Interpreter Lock <global interpreter lock>`, the
62-
threading module operates within a single process, meaning that all threads
63-
share the same memory space. However, the :term:`GIL` limits the performance gains of
64-
threading when it comes to CPU-bound tasks, as only one thread can execute
65-
Python bytecode at a time. Despite this, threads remain a useful tool for
66-
achieving concurrency in many scenarios.
67-
68-
As of Python 3.13, experimental :term:`free-threaded <free threading>` builds can disable the GIL, enabling true parallel execution of threads, but this feature is not available by default. (See :pep:`703`.)
69-
7060
A typical use case for :mod:`threading` includes managing a pool of worker
7161
threads that can process multiple tasks concurrently. This basic example of
7262
creating and starting threads using :class:`~threading.Thread`::
@@ -100,6 +90,21 @@ creating and starting threads using :class:`~threading.Thread`::
10090
for t in threads:
10191
t.join()
10292

93+
GIL and Performance Considerations
94+
----------------------------------
95+
96+
Unlike the :mod:`multiprocessing` module, which uses separate processes to
97+
bypass the :term:`Global Interpreter Lock <global interpreter lock>`, the
98+
threading module operates within a single process, meaning that all threads
99+
share the same memory space. However, the :term:`GIL` limits the performance
100+
gains of threading when it comes to CPU-bound tasks, as only one thread can
101+
execute Python bytecode at a time. Despite this, threads remain a useful tool
102+
for achieving concurrency in many scenarios.
103+
104+
As of Python 3.13, experimental :term:`free-threaded <free threading>` builds
105+
can disable the :term:`GIL`, enabling true parallel execution of threads, but
106+
this feature is not available by default. (See :pep:`703`.)
107+
103108
This module defines the following functions:
104109

105110

0 commit comments

Comments
 (0)