Skip to content

Commit eca2ea8

Browse files
Merge branch 'main' into gh-137056
2 parents e6b5c48 + 377b787 commit eca2ea8

File tree

107 files changed

+2784
-697
lines changed

Some content is hidden

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

107 files changed

+2784
-697
lines changed

Doc/library/asyncio-eventloop.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,12 @@ Opening network connections
611611
to bind the socket locally. The *local_host* and *local_port*
612612
are looked up using :meth:`getaddrinfo`.
613613

614+
.. note::
615+
616+
On Windows, when using the proactor event loop with ``local_addr=None``,
617+
an :exc:`OSError` with :attr:`!errno.WSAEINVAL` will be raised
618+
when running it.
619+
614620
* *remote_addr*, if given, is a ``(remote_host, remote_port)`` tuple used
615621
to connect the socket to a remote address. The *remote_host* and
616622
*remote_port* are looked up using :meth:`getaddrinfo`.

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/codecs.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,36 @@ to :class:`bytes` mappings. They are not supported by :meth:`bytes.decode`
14831483
Restoration of the aliases for the binary transforms.
14841484

14851485

1486+
.. _standalone-codec-functions:
1487+
1488+
Standalone Codec Functions
1489+
^^^^^^^^^^^^^^^^^^^^^^^^^^
1490+
1491+
The following functions provide encoding and decoding functionality similar to codecs,
1492+
but are not available as named codecs through :func:`codecs.encode` or :func:`codecs.decode`.
1493+
They are used internally (for example, by :mod:`pickle`) and behave similarly to the
1494+
``string_escape`` codec that was removed in Python 3.
1495+
1496+
.. function:: codecs.escape_encode(input, errors=None)
1497+
1498+
Encode *input* using escape sequences. Similar to how :func:`repr` on bytes
1499+
produces escaped byte values.
1500+
1501+
*input* must be a :class:`bytes` object.
1502+
1503+
Returns a tuple ``(output, length)`` where *output* is a :class:`bytes`
1504+
object and *length* is the number of bytes consumed.
1505+
1506+
.. function:: codecs.escape_decode(input, errors=None)
1507+
1508+
Decode *input* from escape sequences back to the original bytes.
1509+
1510+
*input* must be a :term:`bytes-like object`.
1511+
1512+
Returns a tuple ``(output, length)`` where *output* is a :class:`bytes`
1513+
object and *length* is the number of bytes consumed.
1514+
1515+
14861516
.. _text-transforms:
14871517

14881518
Text Transforms

Doc/library/concurrent.futures.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ that :class:`ProcessPoolExecutor` will not work in the interactive interpreter.
342342
Calling :class:`Executor` or :class:`Future` methods from a callable submitted
343343
to a :class:`ProcessPoolExecutor` will result in deadlock.
344344

345+
Note that the restrictions on functions and arguments needing to picklable as
346+
per :class:`multiprocessing.Process` apply when using :meth:`~Executor.submit`
347+
and :meth:`~Executor.map` on a :class:`ProcessPoolExecutor`. A function defined
348+
in a REPL or a lambda should not be expected to work.
349+
345350
.. class:: ProcessPoolExecutor(max_workers=None, mp_context=None, initializer=None, initargs=(), max_tasks_per_child=None)
346351

347352
An :class:`Executor` subclass that executes calls asynchronously using a pool

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/http.cookies.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,12 @@ Morsel Objects
148148
in HTTP requests, and is not accessible through JavaScript. This is intended
149149
to mitigate some forms of cross-site scripting.
150150

151-
The attribute :attr:`samesite` specifies that the browser is not allowed to
152-
send the cookie along with cross-site requests. This helps to mitigate CSRF
153-
attacks. Valid values for this attribute are "Strict" and "Lax".
151+
The attribute :attr:`samesite` controls when the browser sends the cookie with
152+
cross-site requests. This helps to mitigate CSRF attacks. Valid values are
153+
"Strict" (only sent with same-site requests), "Lax" (sent with same-site
154+
requests and top-level navigations), and "None" (sent with same-site and
155+
cross-site requests). When using "None", the "secure" attribute must also
156+
be set, as required by modern browsers.
154157

155158
The attribute :attr:`partitioned` indicates to user agents that these
156159
cross-site cookies *should* only be available in the same top-level context

Doc/library/multiprocessing.rst

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ To show the individual process IDs involved, here is an expanded example::
9797
For an explanation of why the ``if __name__ == '__main__'`` part is
9898
necessary, see :ref:`multiprocessing-programming`.
9999

100+
The arguments to :class:`Process` usually need to be unpickleable from within
101+
the child process. If you tried typing the above example directly into a REPL it
102+
could lead to an :exc:`AttributeError` in the child process trying to locate the
103+
*f* function in the ``__main__`` module.
100104

101105

102106
.. _multiprocessing-start-methods:
@@ -233,9 +237,12 @@ processes for a different context. In particular, locks created using
233237
the *fork* context cannot be passed to processes started using the
234238
*spawn* or *forkserver* start methods.
235239

236-
A library which wants to use a particular start method should probably
237-
use :func:`get_context` to avoid interfering with the choice of the
238-
library user.
240+
Libraries using :mod:`multiprocessing` or
241+
:class:`~concurrent.futures.ProcessPoolExecutor` should be designed to allow
242+
their users to provide their own multiprocessing context. Using a specific
243+
context of your own within a library can lead to incompatibilities with the
244+
rest of the library user's application. Always document if your library
245+
requires a specific start method.
239246

240247
.. warning::
241248

@@ -538,9 +545,42 @@ The :mod:`multiprocessing` package mostly replicates the API of the
538545
to pass to *target*.
539546

540547
If a subclass overrides the constructor, it must make sure it invokes the
541-
base class constructor (:meth:`Process.__init__`) before doing anything else
548+
base class constructor (``super().__init__()``) before doing anything else
542549
to the process.
543550

551+
.. note::
552+
553+
In general, all arguments to :class:`Process` must be picklable. This is
554+
frequently observed when trying to create a :class:`Process` or use a
555+
:class:`concurrent.futures.ProcessPoolExecutor` from a REPL with a
556+
locally defined *target* function.
557+
558+
Passing a callable object defined in the current REPL session causes the
559+
child process to die via an uncaught :exc:`AttributeError` exception when
560+
starting as *target* must have been defined within an importable module
561+
in order to be loaded during unpickling.
562+
563+
Example of this uncatchable error from the child::
564+
565+
>>> import multiprocessing as mp
566+
>>> def knigit():
567+
... print("Ni!")
568+
...
569+
>>> process = mp.Process(target=knigit)
570+
>>> process.start()
571+
>>> Traceback (most recent call last):
572+
File ".../multiprocessing/spawn.py", line ..., in spawn_main
573+
File ".../multiprocessing/spawn.py", line ..., in _main
574+
AttributeError: module '__main__' has no attribute 'knigit'
575+
>>> process
576+
<SpawnProcess name='SpawnProcess-1' pid=379473 parent=378707 stopped exitcode=1>
577+
578+
See :ref:`multiprocessing-programming-spawn`. While this restriction is
579+
not true if using the ``"fork"`` start method, as of Python ``3.14`` that
580+
is no longer the default on any platform. See
581+
:ref:`multiprocessing-start-methods`.
582+
See also :gh:`132898`.
583+
544584
.. versionchanged:: 3.3
545585
Added the *daemon* parameter.
546586

@@ -3070,10 +3110,10 @@ start method.
30703110

30713111
More picklability
30723112

3073-
Ensure that all arguments to :meth:`Process.__init__` are picklable.
3074-
Also, if you subclass :class:`~multiprocessing.Process` then make sure that
3075-
instances will be picklable when the :meth:`Process.start
3076-
<multiprocessing.Process.start>` method is called.
3113+
Ensure that all arguments to :class:`~multiprocessing.Process` are
3114+
picklable. Also, if you subclass ``Process.__init__``, you must make sure
3115+
that instances will be picklable when the
3116+
:meth:`Process.start <multiprocessing.Process.start>` method is called.
30773117

30783118
Global variables
30793119

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

Doc/library/ssl.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,13 @@ SSL sockets also have the following additional methods and attributes:
12901290

12911291
.. versionadded:: 3.5
12921292

1293+
.. method:: SSLSocket.group()
1294+
1295+
Return the group used for doing key agreement on this connection. If no
1296+
connection has been established, returns ``None``.
1297+
1298+
.. versionadded:: next
1299+
12931300
.. method:: SSLSocket.compression()
12941301

12951302
Return the compression algorithm being used as a string, or ``None``
@@ -1647,6 +1654,25 @@ to speed up repeated connections from the same clients.
16471654

16481655
.. versionadded:: 3.6
16491656

1657+
.. method:: SSLContext.get_groups(*, include_aliases=False)
1658+
1659+
Get a list of groups implemented for key agreement, taking into
1660+
account the current TLS :attr:`~SSLContext.minimum_version` and
1661+
:attr:`~SSLContext.maximum_version` values. For example::
1662+
1663+
>>> ctx = ssl.create_default_context()
1664+
>>> ctx.minimum_version = ssl.TLSVersion.TLSv1_3
1665+
>>> ctx.maximum_version = ssl.TLSVersion.TLSv1_3
1666+
>>> ctx.get_groups() # doctest: +SKIP
1667+
['secp256r1', 'secp384r1', 'secp521r1', 'x25519', 'x448', ...]
1668+
1669+
By default, this method returns only the preferred IANA names for the
1670+
available groups. However, if the ``include_aliases`` parameter is set to
1671+
:const:`True` this method will also return any associated aliases such as
1672+
the ECDH curve names supported in older versions of OpenSSL.
1673+
1674+
.. versionadded:: next
1675+
16501676
.. method:: SSLContext.set_default_verify_paths()
16511677

16521678
Load a set of default "certification authority" (CA) certificates from
@@ -1672,6 +1698,19 @@ to speed up repeated connections from the same clients.
16721698
TLS 1.3 cipher suites cannot be disabled with
16731699
:meth:`~SSLContext.set_ciphers`.
16741700

1701+
.. method:: SSLContext.set_groups(groups)
1702+
1703+
Set the groups allowed for key agreement for sockets created with this
1704+
context. It should be a string in the `OpenSSL group list format
1705+
<https://docs.openssl.org/master/man3/SSL_CTX_set1_groups_list/>`_.
1706+
1707+
.. note::
1708+
1709+
When connected, the :meth:`SSLSocket.group` method of SSL sockets will
1710+
return the group used for key agreement on that connection.
1711+
1712+
.. versionadded:: next
1713+
16751714
.. method:: SSLContext.set_alpn_protocols(protocols)
16761715

16771716
Specify which protocols the socket should advertise during the SSL/TLS

0 commit comments

Comments
 (0)