Skip to content

Commit 2fd6255

Browse files
authored
Merge branch '3.13' into fix-name-passed-to-task-factory
2 parents 363d336 + c529870 commit 2fd6255

20 files changed

Lines changed: 393 additions & 226 deletions

.github/workflows/mypy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ 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/verify_ensurepip_wheels.py"
1920
- "Tools/build/update_file.py"
21+
- "Tools/build/umarshal.py"
2022
- "Tools/cases_generator/**"
2123
- "Tools/clinic/**"
2224
- "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
@@ -39,6 +39,8 @@ repos:
3939
exclude: Lib/test/tokenizedata/coding20731.py
4040
- id: trailing-whitespace
4141
types_or: [c, inc, python, rst]
42+
- id: trailing-whitespace
43+
files: '\.(gram)$'
4244

4345
- repo: https://github.com/woodruffw/zizmor-pre-commit
4446
rev: v1.6.0

Doc/library/asyncio-dev.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ In addition to enabling the debug mode, consider also:
4646

4747
When the debug mode is enabled:
4848

49-
* asyncio checks for :ref:`coroutines that were not awaited
50-
<asyncio-coroutine-not-scheduled>` and logs them; this mitigates
51-
the "forgotten await" pitfall.
52-
5349
* Many non-threadsafe asyncio APIs (such as :meth:`loop.call_soon` and
5450
:meth:`loop.call_at` methods) raise an exception if they are called
5551
from a wrong thread.

Doc/library/http.server.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,7 @@ provides three different variants:
389389
``'Last-Modified:'`` header with the file's modification time.
390390

391391
Then follows a blank line signifying the end of the headers, and then the
392-
contents of the file are output. If the file's MIME type starts with
393-
``text/`` the file is opened in text mode; otherwise binary mode is used.
392+
contents of the file are output.
394393

395394
For example usage, see the implementation of the ``test`` function
396395
in :source:`Lib/http/server.py`.

Doc/library/pathlib.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,9 +1661,12 @@ The following wildcards are supported in patterns for
16611661
``?``
16621662
Matches one non-separator character.
16631663
``[seq]``
1664-
Matches one character in *seq*.
1664+
Matches one character in *seq*, where *seq* is a sequence of characters.
1665+
Range expressions are supported; for example, ``[a-z]`` matches any lowercase ASCII letter.
1666+
Multiple ranges can be combined: ``[a-zA-Z0-9_]`` matches any ASCII letter, digit, or underscore.
1667+
16651668
``[!seq]``
1666-
Matches one character not in *seq*.
1669+
Matches one character not in *seq*, where *seq* follows the same rules as above.
16671670

16681671
For a literal match, wrap the meta-characters in brackets.
16691672
For example, ``"[?]"`` matches the character ``"?"``.

Doc/library/stdtypes.rst

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

2136+
If *sep* is not specified or is ``None`` and *maxsplit* is ``0``, only
2137+
leading runs of consecutive whitespace are considered.
2138+
2139+
For example::
2140+
2141+
>>> "".split(None, 0)
2142+
[]
2143+
>>> " ".split(None, 0)
2144+
[]
2145+
>>> " foo ".split(maxsplit=0)
2146+
['foo ']
2147+
21362148

21372149
.. index::
21382150
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
@@ -608,8 +672,8 @@ since it is impossible to detect the termination of alien threads.
608672

609673
.. _lock-objects:
610674

611-
Lock Objects
612-
------------
675+
Lock objects
676+
^^^^^^^^^^^^
613677

614678
A primitive lock is a synchronization primitive that is not owned by a
615679
particular thread when locked. In Python, it is currently the lowest level
@@ -698,8 +762,8 @@ All methods are executed atomically.
698762

699763
.. _rlock-objects:
700764

701-
RLock Objects
702-
-------------
765+
RLock objects
766+
^^^^^^^^^^^^^
703767

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

802866
.. _condition-objects:
803867

804-
Condition Objects
805-
-----------------
868+
Condition objects
869+
^^^^^^^^^^^^^^^^^
806870

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

9741038
.. _semaphore-objects:
9751039

976-
Semaphore Objects
977-
-----------------
1040+
Semaphore objects
1041+
^^^^^^^^^^^^^^^^^
9781042

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

10551119
.. _semaphore-examples:
10561120

1057-
:class:`Semaphore` Example
1121+
:class:`Semaphore` example
10581122
^^^^^^^^^^^^^^^^^^^^^^^^^^
10591123

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

10831147
.. _event-objects:
10841148

1085-
Event Objects
1086-
-------------
1149+
Event objects
1150+
^^^^^^^^^^^^^
10871151

10881152
This is one of the simplest mechanisms for communication between threads: one
10891153
thread signals an event and other threads wait for it.
@@ -1139,8 +1203,8 @@ method. The :meth:`~Event.wait` method blocks until the flag is true.
11391203

11401204
.. _timer-objects:
11411205

1142-
Timer Objects
1143-
-------------
1206+
Timer objects
1207+
^^^^^^^^^^^^^
11441208

11451209
This class represents an action that should be run only after a certain amount
11461210
of time has passed --- a timer. :class:`Timer` is a subclass of :class:`Thread`
@@ -1177,8 +1241,8 @@ For example::
11771241
only work if the timer is still in its waiting stage.
11781242

11791243

1180-
Barrier Objects
1181-
---------------
1244+
Barrier objects
1245+
^^^^^^^^^^^^^^^
11821246

11831247
.. versionadded:: 3.2
11841248

Doc/tools/templates/layout.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
{% endblock %}
2727

2828
{% block extrahead %}
29-
{% if builder == "html" and enable_analytics %}
29+
{% if builder == "html" %}
30+
{% if enable_analytics %}
3031
<script defer data-domain="docs.python.org" src="https://analytics.python.org/js/script.outbound-links.js"></script>
31-
{% endif %}
32-
<link rel="canonical" href="https://docs.python.org/3/{{pagename}}.html">
33-
{% if builder != "htmlhelp" %}
32+
{% endif %}
33+
<link rel="canonical" href="https://docs.python.org/3/{{pagename}}.html">
3434
{% if pagename == 'whatsnew/changelog' and not embedded %}
3535
<script type="text/javascript" src="{{ pathto('_static/changelog_search.js', 1) }}"></script>{% endif %}
3636
{% endif %}

Doc/tutorial/controlflow.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,8 @@ scope::
998998
43
999999

10001000
The above example uses a lambda expression to return a function. Another use
1001-
is to pass a small function as an argument::
1001+
is to pass a small function as an argument. For instance, :meth:`list.sort`
1002+
takes a sorting key function *key* which can be a lambda function::
10021003

10031004
>>> pairs = [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')]
10041005
>>> pairs.sort(key=lambda pair: pair[1])

0 commit comments

Comments
 (0)