@@ -6,13 +6,12 @@ Python support for free threading
66
77Starting with the 3.13 release, CPython has support for a build of
88Python called :term: `free threading ` where the :term: `global interpreter lock `
9- (GIL) is disabled. Free-threaded execution allows for full utilization of the
9+ (GIL) is disabled. Free-threaded execution allows for full utilization of the
1010available processing power by running threads in parallel on available CPU cores.
1111While not all software will benefit from this automatically, programs
1212designed with threading in mind will run faster on multi-core hardware.
1313
14- The free-threaded mode continues to be improved with each release.
15- Additionally, third-party packages, in particular ones
14+ Some third-party packages, in particular ones
1615with an :term: `extension module `, may not be ready for use in a
1716free-threaded build, and will re-enable the :term: `GIL `.
1817
@@ -102,7 +101,7 @@ Immortalization
102101
103102In the free-threaded build, some objects are :term: `immortal `.
104103Immortal objects are not deallocated and have reference counts that are
105- never modified. This is done to avoid reference count contention that would
104+ never modified. This is done to avoid reference count contention that would
106105prevent efficient multi-threaded scaling.
107106
108107As of the 3.14 release, immortalization is limited to:
@@ -115,33 +114,26 @@ As of the 3.14 release, immortalization is limited to:
115114Frame objects
116115-------------
117116
118- It is not safe to access :ref: `frame <frame-objects >` objects from other
119- threads. This means that
120- :func: `sys._current_frames ` is generally not safe to use in a free-threaded
121- build. Functions like :func: `inspect.currentframe ` and :func: `sys._getframe `
122- are generally safe as long as the resulting frame object is not passed to
123- another thread.
117+ It is not safe to access :attr: `frame.f_locals ` from a :ref: `frame <frame-objects >`
118+ object if that frame is currently executing in another thread.
119+
124120
125121Iterators
126122---------
127123
128- While sharing the same iterator object between multiple threads is generally not
129- safe from a logical perspective (threads may see duplicate or missing elements
130- when iterating), the 3.14 free-threaded build prevents interpreter crashes
131- that occurred in earlier versions.
124+ It is generally not thread-safe to access the same iterator object from
125+ multiple threads concurrently, and threads may see duplicate or missing
126+ elements.
132127
133128
134129Single-threaded performance
135130---------------------------
136131
137132The free-threaded build has additional overhead when executing Python code
138- compared to the default GIL-enabled build. This overhead was reduced
139- in the 3.14 release (which re-enabled the specializing adaptive
140- interpreter, :pep: `659 `). Reducing this overhead further remains an
141- active development goal, with an aim for 10% or less on the
142- `pyperformance <https://pyperformance.readthedocs.io/ >`_ suite compared to the default GIL-enabled build.
143- Programs that spend most of their time in C extensions or I/O will see
144- less of an impact.
133+ compared to the default GIL-enabled build. The amount of overhead depends
134+ on the workload and hardware. On the pyperformance benchmark suite, the
135+ average overhead ranges from about 1% on macOS aarch64 to 8% on x86-64 Linux
136+ systems.
145137
146138
147139Behavioral changes
0 commit comments