Skip to content

Commit b8c57ee

Browse files
authored
Merge branch 'main' into fix-issue-133604
2 parents d50237c + 62f66ca commit b8c57ee

File tree

90 files changed

+1839
-1194
lines changed

Some content is hidden

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

90 files changed

+1839
-1194
lines changed

.github/workflows/mypy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ on:
1414
- "Lib/tomllib/**"
1515
- "Misc/mypy/**"
1616
- "Tools/build/compute-changes.py"
17+
- "Tools/build/deepfreeze.py"
1718
- "Tools/build/generate_sbom.py"
1819
- "Tools/build/generate-build-details.py"
1920
- "Tools/build/verify_ensurepip_wheels.py"
2021
- "Tools/build/update_file.py"
22+
- "Tools/build/umarshal.py"
2123
- "Tools/cases_generator/**"
2224
- "Tools/clinic/**"
2325
- "Tools/jit/**"

.github/workflows/reusable-context.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ jobs:
9797
run: python Tools/build/compute-changes.py
9898
env:
9999
GITHUB_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
100+
GITHUB_EVENT_NAME: ${{ github.event_name }}
100101
CCF_TARGET_REF: ${{ github.base_ref || github.event.repository.default_branch }}
101102
CCF_HEAD_REF: ${{ github.event.pull_request.head.sha || github.sha }}
102103

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ repos:
4747
exclude: Lib/test/tokenizedata/coding20731.py
4848
- id: trailing-whitespace
4949
types_or: [c, inc, python, rst]
50+
- id: trailing-whitespace
51+
files: '\.(gram)$'
5052

5153
- repo: https://github.com/python-jsonschema/check-jsonschema
5254
rev: 0.33.0

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ Pending removal in Python 3.15
9999

100100
* :mod:`wave`:
101101

102-
* The :meth:`~wave.Wave_read.getmark`, :meth:`!setmark`,
103-
and :meth:`~wave.Wave_read.getmarkers` methods of
102+
* The ``getmark()``, ``setmark()`` and ``getmarkers()`` methods of
104103
the :class:`~wave.Wave_read` and :class:`~wave.Wave_write` classes
105104
have been deprecated since Python 3.13.
106105

Doc/library/fcntl.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@ The module defines the following functions:
107107
passed to the C :c:func:`fcntl` call. The return value after a successful
108108
call is the contents of the buffer, converted to a :class:`bytes` object.
109109
The length of the returned object will be the same as the length of the
110-
*arg* argument. This is limited to 1024 bytes.
110+
*arg* argument.
111111

112112
If the :c:func:`fcntl` call fails, an :exc:`OSError` is raised.
113113

114114
.. note::
115-
If the type or the size of *arg* does not match the type or size
116-
of the argument of the operation (for example, if an integer is
115+
If the type or size of *arg* does not match the type or size
116+
of the operation's argument (for example, if an integer is
117117
passed when a pointer is expected, or the information returned in
118-
the buffer by the operating system is larger than 1024 bytes),
118+
the buffer by the operating system is larger than the size of *arg*),
119119
this is most likely to result in a segmentation violation or
120120
a more subtle data corruption.
121121

@@ -125,6 +125,9 @@ The module defines the following functions:
125125
Add support of arbitrary :term:`bytes-like objects <bytes-like object>`,
126126
not only :class:`bytes`.
127127

128+
.. versionchanged:: next
129+
The size of bytes-like objects is no longer limited to 1024 bytes.
130+
128131

129132
.. function:: ioctl(fd, request, arg=0, mutate_flag=True, /)
130133

@@ -161,8 +164,7 @@ The module defines the following functions:
161164
If the type or size of *arg* does not match the type or size
162165
of the operation's argument (for example, if an integer is
163166
passed when a pointer is expected, or the information returned in
164-
the buffer by the operating system is larger than 1024 bytes,
165-
or the size of the mutable bytes-like object is too small),
167+
the buffer by the operating system is larger than the size of *arg*),
166168
this is most likely to result in a segmentation violation or
167169
a more subtle data corruption.
168170

@@ -185,6 +187,10 @@ The module defines the following functions:
185187
The GIL is always released during a system call.
186188
System calls failing with EINTR are automatically retried.
187189

190+
.. versionchanged:: next
191+
The size of not mutated bytes-like objects is no longer
192+
limited to 1024 bytes.
193+
188194
.. function:: flock(fd, operation, /)
189195

190196
Perform the lock operation *operation* on file descriptor *fd* (file objects providing

Doc/library/logging.rst

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,8 +1342,9 @@ functions.
13421342

13431343
.. function:: basicConfig(**kwargs)
13441344

1345-
Does basic configuration for the logging system by creating a
1346-
:class:`StreamHandler` with a default :class:`Formatter` and adding it to the
1345+
Does basic configuration for the logging system by either creating a
1346+
:class:`StreamHandler` with a default :class:`Formatter`
1347+
or using the given *formatter* instance, and adding it to the
13471348
root logger. The functions :func:`debug`, :func:`info`, :func:`warning`,
13481349
:func:`error` and :func:`critical` will call :func:`basicConfig` automatically
13491350
if no handlers are defined for the root logger.
@@ -1428,6 +1429,19 @@ functions.
14281429
| | which means that it will be treated the |
14291430
| | same as passing 'errors'. |
14301431
+--------------+---------------------------------------------+
1432+
| *formatter* | If specified, set this formatter instance |
1433+
| | (see :ref:`formatter-objects`) |
1434+
| | for all involved handlers. |
1435+
| | If not specified, the default is to create |
1436+
| | and use an instance of |
1437+
| | :class:`logging.Formatter` based on |
1438+
| | arguments *format*, *datefmt* and *style*. |
1439+
| | When *formatter* is specified together with |
1440+
| | any of the three arguments *format*, |
1441+
| | *datefmt* and *style*, a ``ValueError`` is |
1442+
| | raised to signal that these arguments would |
1443+
| | lose meaning otherwise. |
1444+
+--------------+---------------------------------------------+
14311445

14321446
.. versionchanged:: 3.2
14331447
The *style* argument was added.
@@ -1444,6 +1458,9 @@ functions.
14441458
.. versionchanged:: 3.9
14451459
The *encoding* and *errors* arguments were added.
14461460

1461+
.. versionchanged:: 3.15
1462+
The *formatter* argument was added.
1463+
14471464
.. function:: shutdown()
14481465

14491466
Informs the logging system to perform an orderly shutdown by flushing and

Doc/library/stdtypes.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,6 +2269,18 @@ expression support in the :mod:`re` module).
22692269
>>> ' 1 2 3 '.split()
22702270
['1', '2', '3']
22712271

2272+
If *sep* is not specified or is ``None`` and *maxsplit* is ``0``, only
2273+
leading runs of consecutive whitespace are considered.
2274+
2275+
For example::
2276+
2277+
>>> "".split(None, 0)
2278+
[]
2279+
>>> " ".split(None, 0)
2280+
[]
2281+
>>> " foo ".split(maxsplit=0)
2282+
['foo ']
2283+
22722284

22732285
.. index::
22742286
single: universal newlines; str.splitlines method

Doc/library/threading.rst

Lines changed: 89 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,52 @@
1111
This module constructs higher-level threading interfaces on top of the lower
1212
level :mod:`_thread` module.
1313

14+
.. include:: ../includes/wasm-notavail.rst
15+
16+
Introduction
17+
------------
18+
19+
The :mod:`!threading` module provides a way to run multiple `threads
20+
<https://en.wikipedia.org/wiki/Thread_(computing)>`_ (smaller
21+
units of a process) concurrently within a single process. It allows for the
22+
creation and management of threads, making it possible to execute tasks in
23+
parallel, sharing memory space. Threads are particularly useful when tasks are
24+
I/O bound, such as file operations or making network requests,
25+
where much of the time is spent waiting for external resources.
26+
27+
A typical use case for :mod:`!threading` includes managing a pool of worker
28+
threads that can process multiple tasks concurrently. Here's a basic example of
29+
creating and starting threads using :class:`~threading.Thread`::
30+
31+
import threading
32+
import time
33+
34+
def crawl(link, delay=3):
35+
print(f"crawl started for {link}")
36+
time.sleep(delay) # Blocking I/O (simulating a network request)
37+
print(f"crawl ended for {link}")
38+
39+
links = [
40+
"https://python.org",
41+
"https://docs.python.org",
42+
"https://peps.python.org",
43+
]
44+
45+
# Start threads for each link
46+
threads = []
47+
for link in links:
48+
# Using `args` to pass positional arguments and `kwargs` for keyword arguments
49+
t = threading.Thread(target=crawl, args=(link,), kwargs={"delay": 2})
50+
threads.append(t)
51+
52+
# Start each thread
53+
for t in threads:
54+
t.start()
55+
56+
# Wait for all threads to finish
57+
for t in threads:
58+
t.join()
59+
1460
.. versionchanged:: 3.7
1561
This module used to be optional, it is now always available.
1662

@@ -45,7 +91,25 @@ level :mod:`_thread` module.
4591
However, threading is still an appropriate model if you want to run
4692
multiple I/O-bound tasks simultaneously.
4793

48-
.. include:: ../includes/wasm-notavail.rst
94+
GIL and performance considerations
95+
----------------------------------
96+
97+
Unlike the :mod:`multiprocessing` module, which uses separate processes to
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.
104+
105+
As of Python 3.13, experimental :term:`free-threaded <free threading>` builds
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.
110+
111+
Reference
112+
---------
49113

50114
This module defines the following functions:
51115

@@ -62,7 +126,7 @@ This module defines the following functions:
62126

63127
Return the current :class:`Thread` object, corresponding to the caller's thread
64128
of control. If the caller's thread of control was not created through the
65-
:mod:`threading` module, a dummy thread object with limited functionality is
129+
:mod:`!threading` module, a dummy thread object with limited functionality is
66130
returned.
67131

68132
The function ``currentThread`` is a deprecated alias for this function.
@@ -157,13 +221,13 @@ This module defines the following functions:
157221

158222
.. index:: single: trace function
159223

160-
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.
161225
The *func* will be passed to :func:`sys.settrace` for each thread, before its
162226
:meth:`~Thread.run` method is called.
163227

164228
.. function:: settrace_all_threads(func)
165229

166-
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
167231
and all Python threads that are currently executing.
168232

169233
The *func* will be passed to :func:`sys.settrace` for each thread, before its
@@ -186,13 +250,13 @@ This module defines the following functions:
186250

187251
.. index:: single: profile function
188252

189-
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.
190254
The *func* will be passed to :func:`sys.setprofile` for each thread, before its
191255
:meth:`~Thread.run` method is called.
192256

193257
.. function:: setprofile_all_threads(func)
194258

195-
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
196260
and all Python threads that are currently executing.
197261

198262
The *func* will be passed to :func:`sys.setprofile` for each thread, before its
@@ -257,8 +321,8 @@ when implemented, are mapped to module-level functions.
257321
All of the methods described below are executed atomically.
258322

259323

260-
Thread-Local Data
261-
-----------------
324+
Thread-local data
325+
^^^^^^^^^^^^^^^^^
262326

263327
Thread-local data is data whose values are thread specific. If you
264328
have data that you want to be local to a thread, create a
@@ -389,8 +453,8 @@ affects what we see::
389453

390454
.. _thread-objects:
391455

392-
Thread Objects
393-
--------------
456+
Thread objects
457+
^^^^^^^^^^^^^^
394458

395459
The :class:`Thread` class represents an activity that is run in a separate
396460
thread of control. There are two ways to specify the activity: by passing a
@@ -645,8 +709,8 @@ since it is impossible to detect the termination of alien threads.
645709

646710
.. _lock-objects:
647711

648-
Lock Objects
649-
------------
712+
Lock objects
713+
^^^^^^^^^^^^
650714

651715
A primitive lock is a synchronization primitive that is not owned by a
652716
particular thread when locked. In Python, it is currently the lowest level
@@ -738,8 +802,8 @@ All methods are executed atomically.
738802

739803
.. _rlock-objects:
740804

741-
RLock Objects
742-
-------------
805+
RLock objects
806+
^^^^^^^^^^^^^
743807

744808
A reentrant lock is a synchronization primitive that may be acquired multiple
745809
times by the same thread. Internally, it uses the concepts of "owning thread"
@@ -848,8 +912,8 @@ call release as many times the lock has been acquired can lead to deadlock.
848912

849913
.. _condition-objects:
850914

851-
Condition Objects
852-
-----------------
915+
Condition objects
916+
^^^^^^^^^^^^^^^^^
853917

854918
A condition variable is always associated with some kind of lock; this can be
855919
passed in or one will be created by default. Passing one in is useful when
@@ -1026,8 +1090,8 @@ item to the buffer only needs to wake up one consumer thread.
10261090

10271091
.. _semaphore-objects:
10281092

1029-
Semaphore Objects
1030-
-----------------
1093+
Semaphore objects
1094+
^^^^^^^^^^^^^^^^^
10311095

10321096
This is one of the oldest synchronization primitives in the history of computer
10331097
science, invented by the early Dutch computer scientist Edsger W. Dijkstra (he
@@ -1107,7 +1171,7 @@ Semaphores also support the :ref:`context management protocol <with-locks>`.
11071171

11081172
.. _semaphore-examples:
11091173

1110-
:class:`Semaphore` Example
1174+
:class:`Semaphore` example
11111175
^^^^^^^^^^^^^^^^^^^^^^^^^^
11121176

11131177
Semaphores are often used to guard resources with limited capacity, for example,
@@ -1135,8 +1199,8 @@ causes the semaphore to be released more than it's acquired will go undetected.
11351199

11361200
.. _event-objects:
11371201

1138-
Event Objects
1139-
-------------
1202+
Event objects
1203+
^^^^^^^^^^^^^
11401204

11411205
This is one of the simplest mechanisms for communication between threads: one
11421206
thread signals an event and other threads wait for it.
@@ -1192,8 +1256,8 @@ method. The :meth:`~Event.wait` method blocks until the flag is true.
11921256

11931257
.. _timer-objects:
11941258

1195-
Timer Objects
1196-
-------------
1259+
Timer objects
1260+
^^^^^^^^^^^^^
11971261

11981262
This class represents an action that should be run only after a certain amount
11991263
of time has passed --- a timer. :class:`Timer` is a subclass of :class:`Thread`
@@ -1230,8 +1294,8 @@ For example::
12301294
only work if the timer is still in its waiting stage.
12311295

12321296

1233-
Barrier Objects
1234-
---------------
1297+
Barrier objects
1298+
^^^^^^^^^^^^^^^
12351299

12361300
.. versionadded:: 3.2
12371301

0 commit comments

Comments
 (0)