@@ -16,15 +16,15 @@ level :mod:`_thread` module.
1616Introduction
1717------------
1818
19- The :mod: `threading ` module provides a way to run multiple `threads
19+ The :mod: `! threading ` module provides a way to run multiple `threads
2020<https://en.wikipedia.org/wiki/Thread_(computing)> `_ (smaller
2121units of a process) concurrently within a single process. It allows for the
2222creation and management of threads, making it possible to execute tasks in
2323parallel, sharing memory space. Threads are particularly useful when tasks are
24- I/O- bound, such as file operations or making network requests,
24+ I/O bound, such as file operations or making network requests,
2525where much of the time is spent waiting for external resources.
2626
27- A typical use case for :mod: `threading ` includes managing a pool of worker
27+ A typical use case for :mod: `! threading ` includes managing a pool of worker
2828threads that can process multiple tasks concurrently. Here's a basic example of
2929creating and starting threads using :class: `~threading.Thread `::
3030
@@ -91,20 +91,22 @@ creating and starting threads using :class:`~threading.Thread`::
9191 However, threading is still an appropriate model if you want to run
9292 multiple I/O-bound tasks simultaneously.
9393
94- GIL and Performance Considerations
94+ GIL and performance considerations
9595----------------------------------
9696
9797Unlike the :mod: `multiprocessing ` module, which uses separate processes to
98- bypass the :term: `Global Interpreter Lock < global interpreter lock> ` , the
99- threading module operates within a single process, meaning that all threads
100- share the same memory space. However, the :term: ` GIL ` limits the performance
101- gains of threading when it comes to CPU-bound tasks, as only one thread can
102- execute Python bytecode at a time. Despite this, threads remain a useful tool
103- for achieving concurrency in many scenarios.
98+ bypass the :term: `global interpreter lock ` (GIL) , the threading module operates
99+ within a single process, meaning that all threads share the same memory space.
100+ However, the GIL limits the performance gains of threading when it comes to
101+ CPU-bound tasks, as only one thread can execute Python bytecode at a time.
102+ Despite this, threads remain a useful tool for achieving concurrency in many
103+ scenarios.
104104
105105As of Python 3.13, experimental :term: `free-threaded <free threading> ` builds
106- can disable the :term: `GIL `, enabling true parallel execution of threads, but
107- this feature is not available by default. (See :pep: `703 `.)
106+ can disable the GIL, enabling true parallel execution of threads, but this
107+ feature is not available by default (see :pep: `703 `).
108+
109+ .. TODO: At some point this feature will become available by default.
108110
109111 Reference
110112---------
@@ -124,7 +126,7 @@ This module defines the following functions:
124126
125127 Return the current :class: `Thread ` object, corresponding to the caller's thread
126128 of control. If the caller's thread of control was not created through the
127- :mod: `threading ` module, a dummy thread object with limited functionality is
129+ :mod: `! threading ` module, a dummy thread object with limited functionality is
128130 returned.
129131
130132 The function ``currentThread `` is a deprecated alias for this function.
@@ -219,13 +221,13 @@ This module defines the following functions:
219221
220222 .. index :: single: trace function
221223
222- Set a trace function for all threads started from the :mod: `threading ` module.
224+ Set a trace function for all threads started from the :mod: `! threading ` module.
223225 The *func * will be passed to :func: `sys.settrace ` for each thread, before its
224226 :meth: `~Thread.run ` method is called.
225227
226228.. function :: settrace_all_threads(func)
227229
228- Set a trace function for all threads started from the :mod: `threading ` module
230+ Set a trace function for all threads started from the :mod: `! threading ` module
229231 and all Python threads that are currently executing.
230232
231233 The *func * will be passed to :func: `sys.settrace ` for each thread, before its
@@ -248,13 +250,13 @@ This module defines the following functions:
248250
249251 .. index :: single: profile function
250252
251- Set a profile function for all threads started from the :mod: `threading ` module.
253+ Set a profile function for all threads started from the :mod: `! threading ` module.
252254 The *func * will be passed to :func: `sys.setprofile ` for each thread, before its
253255 :meth: `~Thread.run ` method is called.
254256
255257.. function :: setprofile_all_threads(func)
256258
257- Set a profile function for all threads started from the :mod: `threading ` module
259+ Set a profile function for all threads started from the :mod: `! threading ` module
258260 and all Python threads that are currently executing.
259261
260262 The *func * will be passed to :func: `sys.setprofile ` for each thread, before its
@@ -319,7 +321,7 @@ when implemented, are mapped to module-level functions.
319321All of the methods described below are executed atomically.
320322
321323
322- Thread-Local Data
324+ Thread-local data
323325^^^^^^^^^^^^^^^^^
324326
325327Thread-local data is data whose values are thread specific. To manage
@@ -342,7 +344,7 @@ The instance's values will be different for separate threads.
342344
343345.. _thread-objects :
344346
345- Thread Objects
347+ Thread objects
346348^^^^^^^^^^^^^^
347349
348350The :class: `Thread ` class represents an activity that is run in a separate
@@ -577,7 +579,7 @@ since it is impossible to detect the termination of alien threads.
577579
578580.. _lock-objects :
579581
580- Lock Objects
582+ Lock objects
581583^^^^^^^^^^^^
582584
583585A primitive lock is a synchronization primitive that is not owned by a
@@ -670,7 +672,7 @@ All methods are executed atomically.
670672
671673.. _rlock-objects :
672674
673- RLock Objects
675+ RLock objects
674676^^^^^^^^^^^^^
675677
676678A reentrant lock is a synchronization primitive that may be acquired multiple
@@ -773,7 +775,7 @@ call release as many times the lock has been acquired can lead to deadlock.
773775
774776.. _condition-objects :
775777
776- Condition Objects
778+ Condition objects
777779^^^^^^^^^^^^^^^^^
778780
779781A condition variable is always associated with some kind of lock; this can be
@@ -945,7 +947,7 @@ item to the buffer only needs to wake up one consumer thread.
945947
946948.. _semaphore-objects :
947949
948- Semaphore Objects
950+ Semaphore objects
949951^^^^^^^^^^^^^^^^^
950952
951953This is one of the oldest synchronization primitives in the history of computer
@@ -1026,7 +1028,7 @@ Semaphores also support the :ref:`context management protocol <with-locks>`.
10261028
10271029.. _semaphore-examples :
10281030
1029- :class: `Semaphore ` Example
1031+ :class: `Semaphore ` example
10301032^^^^^^^^^^^^^^^^^^^^^^^^^^
10311033
10321034Semaphores are often used to guard resources with limited capacity, for example,
@@ -1054,7 +1056,7 @@ causes the semaphore to be released more than it's acquired will go undetected.
10541056
10551057.. _event-objects :
10561058
1057- Event Objects
1059+ Event objects
10581060^^^^^^^^^^^^^
10591061
10601062This is one of the simplest mechanisms for communication between threads: one
@@ -1111,7 +1113,7 @@ method. The :meth:`~Event.wait` method blocks until the flag is true.
11111113
11121114.. _timer-objects :
11131115
1114- Timer Objects
1116+ Timer objects
11151117^^^^^^^^^^^^^
11161118
11171119This class represents an action that should be run only after a certain amount
@@ -1149,7 +1151,7 @@ For example::
11491151 only work if the timer is still in its waiting stage.
11501152
11511153
1152- Barrier Objects
1154+ Barrier objects
11531155^^^^^^^^^^^^^^^
11541156
11551157.. versionadded :: 3.2
0 commit comments