Skip to content

Commit dd2d43e

Browse files
authored
Merge branch 'main' into Update-doc-process-target-location
2 parents c64de22 + a852c7b commit dd2d43e

File tree

100 files changed

+2808
-1087
lines changed

Some content is hidden

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

100 files changed

+2808
-1087
lines changed

Doc/c-api/init.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,7 +2287,7 @@ The C-API provides a basic mutual exclusion lock.
22872287
should not be used to make concurrency control decisions, as the lock
22882288
state may change immediately after the check.
22892289
2290-
.. versionadded:: next
2290+
.. versionadded:: 3.14
22912291
22922292
.. _python-critical-section-api:
22932293
@@ -2372,7 +2372,7 @@ code triggered by the finalizer blocks and calls :c:func:`PyEval_SaveThread`.
23722372
23732373
On the default build, this macro expands to ``{``.
23742374
2375-
.. versionadded:: next
2375+
.. versionadded:: 3.14
23762376
23772377
.. c:macro:: Py_END_CRITICAL_SECTION()
23782378
@@ -2418,7 +2418,7 @@ code triggered by the finalizer blocks and calls :c:func:`PyEval_SaveThread`.
24182418
24192419
On the default build, this macro expands to ``{``.
24202420
2421-
.. versionadded:: next
2421+
.. versionadded:: 3.14
24222422
24232423
.. c:macro:: Py_END_CRITICAL_SECTION2()
24242424

Doc/c-api/perfmaps.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
Support for Perf Maps
66
----------------------
77

8-
On supported platforms (as of this writing, only Linux), the runtime can take
8+
On supported platforms (Linux and macOS), the runtime can take
99
advantage of *perf map files* to make Python functions visible to an external
10-
profiling tool (such as `perf <https://perf.wiki.kernel.org/index.php/Main_Page>`_).
11-
A running process may create a file in the ``/tmp`` directory, which contains entries
12-
that can map a section of executable code to a name. This interface is described in the
10+
profiling tool (such as `perf <https://perf.wiki.kernel.org/index.php/Main_Page>`_ or
11+
`samply <https://github.com/mstange/samply/>`_). A running process may create a
12+
file in the ``/tmp`` directory, which contains entries that can map a section
13+
of executable code to a name. This interface is described in the
1314
`documentation of the Linux Perf tool <https://git.kernel.org/pub/scm/linux/
1415
kernel/git/torvalds/linux.git/tree/tools/perf/Documentation/jit-interface.txt>`_.
1516

Doc/extending/extending.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ and initialize it by calling :c:func:`PyErr_NewException` in the module's
214214

215215
SpamError = PyErr_NewException("spam.error", NULL, NULL);
216216

217-
Since :c:data:`!SpamError` is a global variable, it will be overwitten every time
217+
Since :c:data:`!SpamError` is a global variable, it will be overwritten every time
218218
the module is reinitialized, when the :c:data:`Py_mod_exec` function is called.
219219

220220
For now, let's avoid the issue: we will block repeated initialization by raising an

Doc/howto/free-threading-extensions.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ that return :term:`strong references <strong reference>`.
161161
+===================================+===================================+
162162
| :c:func:`PyList_GetItem` | :c:func:`PyList_GetItemRef` |
163163
+-----------------------------------+-----------------------------------+
164+
| :c:func:`PyList_GET_ITEM` | :c:func:`PyList_GetItemRef` |
165+
+-----------------------------------+-----------------------------------+
164166
| :c:func:`PyDict_GetItem` | :c:func:`PyDict_GetItemRef` |
165167
+-----------------------------------+-----------------------------------+
166168
| :c:func:`PyDict_GetItemWithError` | :c:func:`PyDict_GetItemRef` |

Doc/howto/perf_profiling.rst

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,35 @@
22

33
.. _perf_profiling:
44

5-
==============================================
6-
Python support for the Linux ``perf`` profiler
7-
==============================================
5+
========================================================
6+
Python support for the ``perf map`` compatible profilers
7+
========================================================
88

99
:author: Pablo Galindo
1010

11-
`The Linux perf profiler <https://perf.wiki.kernel.org>`_
12-
is a very powerful tool that allows you to profile and obtain
13-
information about the performance of your application.
14-
``perf`` also has a very vibrant ecosystem of tools
15-
that aid with the analysis of the data that it produces.
11+
`The Linux perf profiler <https://perf.wiki.kernel.org>`_ and
12+
`samply <https://github.com/mstange/samply>`_ are powerful tools that allow you to
13+
profile and obtain information about the performance of your application.
14+
Both tools have vibrant ecosystems that aid with the analysis of the data they produce.
1615

17-
The main problem with using the ``perf`` profiler with Python applications is that
18-
``perf`` only gets information about native symbols, that is, the names of
16+
The main problem with using these profilers with Python applications is that
17+
they only get information about native symbols, that is, the names of
1918
functions and procedures written in C. This means that the names and file names
20-
of Python functions in your code will not appear in the output of ``perf``.
19+
of Python functions in your code will not appear in the profiler output.
2120

2221
Since Python 3.12, the interpreter can run in a special mode that allows Python
23-
functions to appear in the output of the ``perf`` profiler. When this mode is
22+
functions to appear in the output of compatible profilers. When this mode is
2423
enabled, the interpreter will interpose a small piece of code compiled on the
25-
fly before the execution of every Python function and it will teach ``perf`` the
24+
fly before the execution of every Python function and it will teach the profiler the
2625
relationship between this piece of code and the associated Python function using
2726
:doc:`perf map files <../c-api/perfmaps>`.
2827

2928
.. note::
3029

31-
Support for the ``perf`` profiler is currently only available for Linux on
32-
select architectures. Check the output of the ``configure`` build step or
30+
Support for profiling is available on Linux and macOS on select architectures.
31+
Perf is available on Linux, while samply can be used on both Linux and macOS.
32+
samply support on macOS is available starting from Python 3.15.
33+
Check the output of the ``configure`` build step or
3334
check the output of ``python -m sysconfig | grep HAVE_PERF_TRAMPOLINE``
3435
to see if your system is supported.
3536

@@ -148,6 +149,31 @@ Instead, if we run the same experiment with ``perf`` support enabled we get:
148149
149150
150151
152+
Using the samply profiler
153+
-------------------------
154+
155+
samply is a modern profiler that can be used as an alternative to perf.
156+
It uses the same perf map files that Python generates, making it compatible
157+
with Python's profiling support. samply is particularly useful on macOS
158+
where perf is not available.
159+
160+
To use samply with Python, first install it following the instructions at
161+
https://github.com/mstange/samply, then run::
162+
163+
$ samply record PYTHONPERFSUPPORT=1 python my_script.py
164+
165+
This will open a web interface where you can analyze the profiling data
166+
interactively. The advantage of samply is that it provides a modern
167+
web-based interface for analyzing profiling data and works on both Linux
168+
and macOS.
169+
170+
On macOS, samply support requires Python 3.15 or later. Also on macOS, samply
171+
can't profile signed Python executables due to restrictions by macOS. You can
172+
profile with Python binaries that you've compiled yourself, or which are
173+
unsigned or locally-signed (such as anything installed by Homebrew). In
174+
order to attach to running processes on macOS, run ``samply setup`` once (and
175+
every time samply is updated) to self-sign the samply binary.
176+
151177
How to enable ``perf`` profiling support
152178
----------------------------------------
153179

Doc/library/asyncio-queue.rst

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,34 @@ Queue
102102

103103
.. method:: shutdown(immediate=False)
104104

105-
Shut down the queue, making :meth:`~Queue.get` and :meth:`~Queue.put`
105+
Put a :class:`Queue` instance into a shutdown mode.
106+
107+
The queue can no longer grow.
108+
Future calls to :meth:`~Queue.put` raise :exc:`QueueShutDown`.
109+
Currently blocked callers of :meth:`~Queue.put` will be unblocked
110+
and will raise :exc:`QueueShutDown` in the formerly blocked thread.
111+
112+
If *immediate* is false (the default), the queue can be wound
113+
down normally with :meth:`~Queue.get` calls to extract tasks
114+
that have already been loaded.
115+
116+
And if :meth:`~Queue.task_done` is called for each remaining task, a
117+
pending :meth:`~Queue.join` will be unblocked normally.
118+
119+
Once the queue is empty, future calls to :meth:`~Queue.get` will
106120
raise :exc:`QueueShutDown`.
107121

108-
By default, :meth:`~Queue.get` on a shut down queue will only
109-
raise once the queue is empty. Set *immediate* to true to make
110-
:meth:`~Queue.get` raise immediately instead.
122+
If *immediate* is true, the queue is terminated immediately.
123+
The queue is drained to be completely empty and the count
124+
of unfinished tasks is reduced by the number of tasks drained.
125+
If unfinished tasks is zero, callers of :meth:`~Queue.join`
126+
are unblocked. Also, blocked callers of :meth:`~Queue.get`
127+
are unblocked and will raise :exc:`QueueShutDown` because the
128+
queue is empty.
111129

112-
All blocked callers of :meth:`~Queue.put` and :meth:`~Queue.get`
113-
will be unblocked. If *immediate* is true, a task will be marked
114-
as done for each remaining item in the queue, which may unblock
115-
callers of :meth:`~Queue.join`.
130+
Use caution when using :meth:`~Queue.join` with *immediate* set
131+
to true. This unblocks the join even when no work has been done
132+
on the tasks, violating the usual invariant for joining a queue.
116133

117134
.. versionadded:: 3.13
118135

@@ -129,9 +146,6 @@ Queue
129146
call was received for every item that had been :meth:`~Queue.put`
130147
into the queue).
131148

132-
``shutdown(immediate=True)`` calls :meth:`task_done` for each
133-
remaining item in the queue.
134-
135149
Raises :exc:`ValueError` if called more times than there were
136150
items placed in the queue.
137151

Doc/library/bdb.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,8 @@ The :mod:`bdb` module also defines two classes:
192192
entered.
193193
* ``"return"``: A function or other code block is about to return.
194194
* ``"exception"``: An exception has occurred.
195-
* ``"c_call"``: A C function is about to be called.
196-
* ``"c_return"``: A C function has returned.
197-
* ``"c_exception"``: A C function has raised an exception.
198195

199-
For the Python events, specialized functions (see below) are called. For
200-
the C events, no action is taken.
196+
For all the events, specialized functions (see below) are called.
201197

202198
The *arg* parameter depends on the previous event.
203199

Doc/library/concurrent.interpreters.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ makes them similar to processes, but they still enjoy in-process
134134
efficiency, like threads.
135135

136136
All that said, interpreters do naturally support certain flavors of
137-
concurrency, as a powerful side effect of that isolation.
137+
concurrency.
138138
There's a powerful side effect of that isolation. It enables a
139139
different approach to concurrency than you can take with async or
140140
threads. It's a similar concurrency model to CSP or the actor model,

Doc/library/importlib.resources.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ within *packages*.
1616
"Resources" are file-like resources associated with a module or package in
1717
Python. The resources may be contained directly in a package, within a
1818
subdirectory contained in that package, or adjacent to modules outside a
19-
package. Resources may be text or binary. As a result, Python module sources
20-
(.py) of a package and compilation artifacts (pycache) are technically
21-
de-facto resources of that package. In practice, however, resources are
22-
primarily those non-Python artifacts exposed specifically by the package
23-
author.
19+
package. Resources may be text or binary. As a result, a package's Python
20+
module sources (.py), compilation artifacts (pycache), and installation
21+
artifacts (like :func:`reserved filenames <os.path.isreserved>`
22+
in directories) are technically de-facto resources of that package.
23+
In practice, however, resources are primarily those non-Python artifacts
24+
exposed specifically by the package author.
2425

2526
Resources can be opened or read in either binary or text mode.
2627

Doc/library/queue.rst

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,6 @@ fully processed by daemon consumer threads.
187187
processed (meaning that a :meth:`task_done` call was received for every item
188188
that had been :meth:`put` into the queue).
189189

190-
``shutdown(immediate=True)`` calls :meth:`task_done` for each remaining item
191-
in the queue.
192-
193190
Raises a :exc:`ValueError` if called more times than there were items placed in
194191
the queue.
195192

@@ -204,6 +201,9 @@ fully processed by daemon consumer threads.
204201
count of unfinished tasks drops to zero, :meth:`join` unblocks.
205202

206203

204+
Waiting for task completion
205+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
206+
207207
Example of how to wait for enqueued tasks to be completed::
208208

209209
import threading
@@ -233,22 +233,39 @@ Example of how to wait for enqueued tasks to be completed::
233233
Terminating queues
234234
^^^^^^^^^^^^^^^^^^
235235

236-
:class:`Queue` objects can be made to prevent further interaction by shutting
237-
them down.
236+
When no longer needed, :class:`Queue` objects can be wound down
237+
until empty or terminated immediately with a hard shutdown.
238238

239239
.. method:: Queue.shutdown(immediate=False)
240240

241-
Shut down the queue, making :meth:`~Queue.get` and :meth:`~Queue.put` raise
242-
:exc:`ShutDown`.
241+
Put a :class:`Queue` instance into a shutdown mode.
242+
243+
The queue can no longer grow.
244+
Future calls to :meth:`~Queue.put` raise :exc:`ShutDown`.
245+
Currently blocked callers of :meth:`~Queue.put` will be unblocked
246+
and will raise :exc:`ShutDown` in the formerly blocked thread.
247+
248+
If *immediate* is false (the default), the queue can be wound
249+
down normally with :meth:`~Queue.get` calls to extract tasks
250+
that have already been loaded.
251+
252+
And if :meth:`~Queue.task_done` is called for each remaining task, a
253+
pending :meth:`~Queue.join` will be unblocked normally.
254+
255+
Once the queue is empty, future calls to :meth:`~Queue.get` will
256+
raise :exc:`ShutDown`.
243257

244-
By default, :meth:`~Queue.get` on a shut down queue will only raise once the
245-
queue is empty. Set *immediate* to true to make :meth:`~Queue.get` raise
246-
immediately instead.
258+
If *immediate* is true, the queue is terminated immediately.
259+
The queue is drained to be completely empty and the count
260+
of unfinished tasks is reduced by the number of tasks drained.
261+
If unfinished tasks is zero, callers of :meth:`~Queue.join`
262+
are unblocked. Also, blocked callers of :meth:`~Queue.get`
263+
are unblocked and will raise :exc:`ShutDown` because the
264+
queue is empty.
247265

248-
All blocked callers of :meth:`~Queue.put` and :meth:`~Queue.get` will be
249-
unblocked. If *immediate* is true, a task will be marked as done for each
250-
remaining item in the queue, which may unblock callers of
251-
:meth:`~Queue.join`.
266+
Use caution when using :meth:`~Queue.join` with *immediate* set
267+
to true. This unblocks the join even when no work has been done
268+
on the tasks, violating the usual invariant for joining a queue.
252269

253270
.. versionadded:: 3.13
254271

0 commit comments

Comments
 (0)