Skip to content

Commit 40bc434

Browse files
Merge branch 'main' into fix-module-file-docs
2 parents 22d9aa0 + 494f2e3 commit 40bc434

230 files changed

Lines changed: 5623 additions & 3680 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/CODEOWNERS

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
.azure-pipelines/ @AA-Turner
6464

6565
# GitHub & related scripts
66-
.github/ @ezio-melotti @hugovk @AA-Turner @webknjaz
66+
.github/ @ezio-melotti @hugovk @AA-Turner @webknjaz @itamaro
6767
Tools/build/compute-changes.py @AA-Turner @hugovk @webknjaz
6868
Lib/test/test_tools/test_compute_changes.py @AA-Turner @hugovk @webknjaz
6969
Tools/build/verify_ensurepip_wheels.py @AA-Turner @pfmoore @pradyunsg
@@ -73,19 +73,19 @@ Tools/build/verify_ensurepip_wheels.py @AA-Turner @pfmoore @pradyunsg
7373
.ruff.toml @hugovk @AlexWaygood @AA-Turner
7474

7575
# Patchcheck
76-
Tools/patchcheck/ @AA-Turner
76+
Tools/patchcheck/ @AA-Turner @itamaro
7777

7878

7979
# ----------------------------------------------------------------------------
8080
# Build System
8181
# ----------------------------------------------------------------------------
8282

8383
# Autotools
84-
configure* @erlend-aasland @corona10 @AA-Turner @emmatyping
85-
Makefile.pre.in @erlend-aasland @AA-Turner @emmatyping
86-
Modules/makesetup @erlend-aasland @AA-Turner @emmatyping
87-
Modules/Setup* @erlend-aasland @AA-Turner @emmatyping
88-
Tools/build/regen-configure.sh @AA-Turner
84+
configure* @erlend-aasland @corona10 @AA-Turner @emmatyping @itamaro
85+
Makefile.pre.in @erlend-aasland @AA-Turner @emmatyping @itamaro
86+
Modules/makesetup @erlend-aasland @AA-Turner @emmatyping @itamaro
87+
Modules/Setup* @erlend-aasland @AA-Turner @emmatyping @itamaro
88+
Tools/build/regen-configure.sh @AA-Turner @itamaro
8989

9090
# generate-build-details
9191
Tools/build/generate-build-details.py @FFY00

.github/SECURITY.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
# Security Policy
22

3-
## Supported Versions
3+
Python [provides a security policy and threat model](https://devguide.python.org/security/policy/)
4+
in the Python Development Guide documenting what bugs are vulnerabilities,
5+
how to structure reports, and what versions of Python accept reports.
46

5-
The Python team applies security fixes according to the table
6-
in [the devguide](
7-
https://devguide.python.org/versions/#supported-versions
8-
).
7+
Python Security Response Team (PSRT) members
8+
balance security work against many other responsibilities. Please be thoughtful
9+
about the time and attention your report requires. Repeated failure to respect
10+
the security policy will result in future reports being rejected, or the
11+
reporter being banned from the ``python`` GitHub organization, regardless of
12+
technical merit.
913

1014
## Reporting a Vulnerability
1115

12-
Please read the guidelines on reporting security issues [on the
13-
official website](https://www.python.org/dev/security/) for
14-
instructions on how to report a security-related problem to
15-
the Python team responsibly.
16+
The [Python security policy](https://devguide.python.org/security/policy/)
17+
documents [how to submit a vulnerability report](https://devguide.python.org/security/policy/#how-to-submit-a-vulnerability-report)
18+
using GitHub Security Advisories. Please read the security policy
19+
prior to filing a vulnerability report, especially the section on [what information to
20+
include and exclude](https://devguide.python.org/security/policy/#what-to-include-and-how-to-structure-a-vulnerability-report)
21+
in vulnerability reports. Following the security policy means the PSRT can
22+
quickly and efficiently triage your report, not following the security policy
23+
will only delay triaging your report.
1624

17-
To reach the response team, email `security at python dot org`.

Doc/c-api/exceptions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ an error value).
412412
413413
.. c:function:: int PyErr_WarnFormat(PyObject *category, Py_ssize_t stack_level, const char *format, ...)
414414
415-
Function similar to :c:func:`PyErr_WarnEx`, but use
415+
Function similar to :c:func:`PyErr_WarnEx`, but uses
416416
:c:func:`PyUnicode_FromFormat` to format the warning message. *format* is
417417
an ASCII-encoded string.
418418
@@ -1392,7 +1392,7 @@ Tracebacks
13921392
13931393
This function will return ``NULL`` on success, or an error message on error.
13941394
1395-
This function is meant to debug debug situations such as segfaults, fatal
1395+
This function is meant to debug situations such as segfaults, fatal
13961396
errors, and similar. It calls :c:func:`PyUnstable_DumpTraceback` for each
13971397
thread. It only writes the tracebacks of the first *max_threads* threads,
13981398
further output is truncated with the line ``...``. If *max_threads* is 0, the

Doc/c-api/threads.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,10 +736,10 @@ Low-level APIs
736736
.. c:function:: PyObject* PyThreadState_GetDict()
737737
738738
Return a dictionary in which extensions can store thread-specific state
739-
information. Each extension should use a unique key to use to store state in
739+
information. Each extension should use a unique key to store a state in
740740
the dictionary. It is okay to call this function when no :term:`thread state`
741741
is :term:`attached <attached thread state>`. If this function returns
742-
``NULL``, no exception has been raised and the caller should assume no
742+
``NULL`` and no exception has been raised, then the caller should assume no
743743
thread state is attached.
744744
745745

Doc/c-api/typehints.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ two types exist -- :ref:`GenericAlias <types-genericalias>` and
3131
static PyMethodDef my_obj_methods[] = {
3232
// Other methods.
3333
...
34-
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, "See PEP 585"}
34+
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, "my_obj is generic over its contained type"}
3535
...
3636
}
3737

Doc/conf.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,6 @@
349349
\sphinxstrong{Python Software Foundation}\\
350350
Email: \sphinxemail{docs@python.org}
351351
}
352-
\let\Verbatim=\OriginalVerbatim
353-
\let\endVerbatim=\endOriginalVerbatim
354352
\setcounter{tocdepth}{2}
355353
''',
356354
# The paper size ('letterpaper' or 'a4paper').

Doc/deprecations/pending-removal-in-3.21.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Pending removal in Python 3.21
22
------------------------------
33

4+
* :mod:`abc`
5+
6+
* Soft-deprecated since Python 3.3 :class:`abc.abstractclassmethod`,
7+
:class:`abc.abstractstaticmethod`, and :class:`abc.abstractproperty`
8+
now raise a :exc:`DeprecationWarning`.
9+
These classes will be removed in Python 3.21, instead
10+
use :func:`abc.abstractmethod` with :func:`classmethod`,
11+
:func:`staticmethod`, and :class:`property` respectively.
12+
413
* :mod:`ast`:
514

615
* Classes ``slice``, ``Index``, ``ExtSlice``, ``Suite``, ``Param``,

Doc/howto/a-conceptual-overview-of-asyncio.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ The terms "coroutine function" and "coroutine object" are often conflated
115115
as coroutine.
116116
That can be confusing!
117117
In this article, coroutine specifically refers to a coroutine object, or more
118-
precisely, an instance of :data:`types.CoroutineType` (native coroutine).
118+
precisely, an instance of :class:`types.CoroutineType` (native coroutine).
119119
Note that coroutines can also exist as instances of
120120
:class:`collections.abc.Coroutine` -- a distinction that matters for type
121121
checking.

Doc/howto/free-threading-python.rst

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,132 @@ to false. If the flag is true then the :class:`warnings.catch_warnings`
165165
context manager uses a context variable for warning filters. If the flag is
166166
false then :class:`~warnings.catch_warnings` modifies the global filters list,
167167
which is not thread-safe. See the :mod:`warnings` module for more details.
168+
169+
170+
Increased memory usage
171+
----------------------
172+
173+
The free-threaded build will typically use more memory compared to the default
174+
build. There are multiple reasons for this, mostly due to design decisions.
175+
176+
177+
All interned strings are immortal
178+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
179+
180+
For modern Python versions (since version 2.3), interning a string (e.g. with
181+
:func:`sys.intern`) does not cause it to become immortal. Instead, if the last
182+
reference to that string disappears, it will be removed from the interned
183+
string table. This is not the case for the free-threaded build and any interned
184+
string will become immortal, surviving until interpreter shutdown.
185+
186+
187+
Non-GC objects have a larger object header
188+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
189+
190+
The free-threaded build uses a different :c:type:`PyObject` structure. Instead
191+
of having the GC related information allocated before the :c:type:`PyObject`
192+
structure, like in the default build, the GC related info is part of the normal
193+
object header. For example, on the AMD64 platform, ``None`` uses 32 bytes on
194+
the free-threaded build vs 16 bytes for the default build. GC objects (such as
195+
dicts and lists) are the same size for both builds since the free-threaded
196+
build does not use additional space for the GC info.
197+
198+
199+
QSBR can delay freeing of memory
200+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
201+
202+
In order to safely implement lock-free data structures, a safe memory
203+
reclamation (SMR) scheme is used, known as quiescent state-based reclamation
204+
(QSBR). This means that the memory backing data structures allowing lock-free
205+
access will use QSBR, which defers the free operation, rather than immediately
206+
freeing the memory. Two examples of these data structures are the list object
207+
and the dictionary keys object. See ``InternalDocs/qsbr.md`` in the CPython
208+
source tree for more details on how QSBR is implemented. Running
209+
:func:`gc.collect` should cause all memory being held by QSBR to be actually
210+
freed. Note that even when QSBR frees the memory, the underlying memory
211+
allocator may not immediately return that memory to the OS and so the resident
212+
set size (RSS) of the process might not decrease.
213+
214+
215+
mimalloc allocator vs pymalloc
216+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
217+
218+
The default build will normally use the "pymalloc" memory allocator for small
219+
allocations (512 bytes or smaller). The free-threaded build does not use
220+
pymalloc and allocates all Python objects using the "mimalloc" allocator. The
221+
pymalloc allocator has the following properties that help keep memory usage
222+
low: small per-allocated-block overhead, effective memory fragmentation
223+
prevention, and quick return of free memory to the operating system. The
224+
mimalloc allocator does quite well in these respects as well but can have some
225+
more overhead.
226+
227+
In the free-threaded build, mimalloc manages memory in a number of separate
228+
heaps (currently four). For example, all GC supporting objects are allocated
229+
from their own heap. Using separate heaps means that free memory in one heap
230+
cannot be used for an allocation that uses another heap. Also, some heaps are
231+
configured to use QSBR (quiescent-state based reclamation) when freeing the
232+
memory that backs up the heap (known as "pages" in mimalloc terminology). The
233+
use of QSBR creates a delay between all memory blocks for a page being freed
234+
and the memory page being released, either for new allocations or back to the
235+
OS.
236+
237+
The mimalloc allocator also defers returning freed memory back to the OS. You
238+
can reduce that delay by setting the environment variable
239+
:envvar:`!MIMALLOC_PURGE_DELAY` to ``0``. Note that this will likely reduce
240+
the performance of the allocator.
241+
242+
243+
Free-threaded reference counting can cause objects to live longer
244+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
245+
246+
In the default build, when an object's reference count reaches zero, it is
247+
normally deallocated. The free-threaded build uses "biased reference
248+
counting", with a fast-path for objects "owned" by the current thread and a
249+
slow path for other objects. See :pep:`703` for additional details. Any time
250+
an object's reference count ends up in a "queued" state, deallocation can be
251+
deferred. The queued state is cleared from the "eval breaker" section of the
252+
bytecode evaluator.
253+
254+
The free-threaded build also allows a different mode of reference counting,
255+
known as "deferred reference counting". This mode is enabled by setting a flag
256+
on a per-object basis. Deferred reference counting is enabled for the
257+
following types:
258+
259+
* module objects
260+
* module top-level functions
261+
* class methods defined in the class scope
262+
* descriptor objects
263+
* thread-local objects, created by :class:`threading.local`
264+
265+
When deferred reference counting is enabled, references from Python function
266+
stacks are not added to the reference count. This scheme reduces the overhead
267+
of reference counting, especially for objects used from multiple threads.
268+
Because the stack references are not counted, objects with deferred reference
269+
counting are not immediately freed when their internal reference count goes to
270+
zero. Instead, they are examined by the next GC run and, if no stack
271+
references to them are found, they are freed. This means these objects are
272+
freed by the GC and not when their reference count goes to zero, as is typical.
273+
274+
275+
Per-thread reference counting can delay freeing objects
276+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
277+
278+
To avoid contention on the reference count fields of frequently shared
279+
objects, the free-threaded build also uses "per-thread reference counting"
280+
for a few selected object types. Rather than updating a single shared
281+
reference count, each thread maintains its own local reference count array,
282+
indexed by a unique id assigned to the object. The true reference count is
283+
only computed by summing the per-thread counts when the object's local
284+
count drops to zero. Per-thread reference counting is currently used for:
285+
286+
* heap type objects (classes created in Python)
287+
* code objects
288+
* the ``__dict__`` of module objects
289+
290+
Because the per-thread counts must be merged back to the object before it
291+
can be deallocated, objects using per-thread reference counting are
292+
typically freed later than they would be in the default build. In
293+
particular, such an object is usually not freed until the thread that
294+
referenced it reaches a safe point (for example, in the "eval breaker"
295+
section of the bytecode evaluator) or exits. Running :func:`gc.collect`
296+
will merge the per-thread counts and allow these objects to be freed.

Doc/library/_thread.rst

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ This module defines the following constants and functions:
3636
This is now a synonym of the built-in :exc:`RuntimeError`.
3737

3838

39-
.. data:: LockType
40-
41-
This is the type of lock objects.
42-
43-
4439
.. function:: start_new_thread(function, args[, kwargs])
4540

4641
Start a new thread and return its identifier. The thread executes the
@@ -162,58 +157,66 @@ This module defines the following constants and functions:
162157
.. versionadded:: 3.2
163158

164159

165-
Lock objects have the following methods:
160+
.. raw:: html
161+
162+
<!-- Keep the old URL fragments working (see gh-89554) -->
163+
<span id='thread.lock.acquire'></span>
164+
<span id='thread.lock.release'></span>
165+
<span id='thread.lock.locked'></span>
166166

167+
.. class:: LockType
167168

168-
.. method:: lock.acquire(blocking=True, timeout=-1)
169+
This is the type of lock objects.
169170

170-
Without any optional argument, this method acquires the lock unconditionally, if
171-
necessary waiting until it is released by another thread (only one thread at a
172-
time can acquire a lock --- that's their reason for existence).
171+
Lock objects have the following methods:
173172

174-
If the *blocking* argument is present, the action depends on its
175-
value: if it is false, the lock is only acquired if it can be acquired
176-
immediately without waiting, while if it is true, the lock is acquired
177-
unconditionally as above.
173+
.. method:: acquire(blocking=True, timeout=-1)
178174

179-
If the floating-point *timeout* argument is present and positive, it
180-
specifies the maximum wait time in seconds before returning. A negative
181-
*timeout* argument specifies an unbounded wait. You cannot specify
182-
a *timeout* if *blocking* is false.
175+
Without any optional argument, this method acquires the lock unconditionally, if
176+
necessary waiting until it is released by another thread (only one thread at a
177+
time can acquire a lock --- that's their reason for existence).
183178

184-
The return value is ``True`` if the lock is acquired successfully,
185-
``False`` if not.
179+
If the *blocking* argument is present, the action depends on its
180+
value: if it is false, the lock is only acquired if it can be acquired
181+
immediately without waiting, while if it is true, the lock is acquired
182+
unconditionally as above.
186183

187-
.. versionchanged:: 3.2
188-
The *timeout* parameter is new.
184+
If the floating-point *timeout* argument is present and positive, it
185+
specifies the maximum wait time in seconds before returning. A negative
186+
*timeout* argument specifies an unbounded wait. You cannot specify
187+
a *timeout* if *blocking* is false.
189188

190-
.. versionchanged:: 3.2
191-
Lock acquires can now be interrupted by signals on POSIX.
189+
The return value is ``True`` if the lock is acquired successfully,
190+
``False`` if not.
192191

193-
.. versionchanged:: 3.14
194-
Lock acquires can now be interrupted by signals on Windows.
192+
.. versionchanged:: 3.2
193+
The *timeout* parameter is new.
195194

195+
.. versionchanged:: 3.2
196+
Lock acquires can now be interrupted by signals on POSIX.
196197

197-
.. method:: lock.release()
198+
.. versionchanged:: 3.14
199+
Lock acquires can now be interrupted by signals on Windows.
198200

199-
Releases the lock. The lock must have been acquired earlier, but not
200-
necessarily by the same thread.
201+
.. method:: release()
201202

203+
Releases the lock. The lock must have been acquired earlier, but not
204+
necessarily by the same thread.
202205

203-
.. method:: lock.locked()
206+
.. method:: locked()
204207

205-
Return the status of the lock: ``True`` if it has been acquired by some thread,
206-
``False`` if not.
208+
Return the status of the lock: ``True`` if it has been acquired by some thread,
209+
``False`` if not.
207210

208-
In addition to these methods, lock objects can also be used via the
209-
:keyword:`with` statement, e.g.::
211+
In addition to these methods, lock objects can also be used via the
212+
:keyword:`with` statement, e.g.::
210213

211-
import _thread
214+
import _thread
212215

213-
a_lock = _thread.allocate_lock()
216+
a_lock = _thread.allocate_lock()
214217

215-
with a_lock:
216-
print("a_lock is locked while this executes")
218+
with a_lock:
219+
print("a_lock is locked while this executes")
217220

218221
**Caveats:**
219222

0 commit comments

Comments
 (0)