Skip to content

Commit b87bf83

Browse files
committed
Deploying to gh-pages from @ a8c0d8e 🚀
1 parent 9ca4003 commit b87bf83

File tree

566 files changed

+2042
-1760
lines changed

Some content is hidden

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

566 files changed

+2042
-1760
lines changed

_sources/howto/free-threading-extensions.rst.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ that return :term:`strong references <strong reference>`.
159159
+===================================+===================================+
160160
| :c:func:`PyList_GetItem` | :c:func:`PyList_GetItemRef` |
161161
+-----------------------------------+-----------------------------------+
162+
| :c:func:`PyList_GET_ITEM` | :c:func:`PyList_GetItemRef` |
163+
+-----------------------------------+-----------------------------------+
162164
| :c:func:`PyDict_GetItem` | :c:func:`PyDict_GetItemRef` |
163165
+-----------------------------------+-----------------------------------+
164166
| :c:func:`PyDict_GetItemWithError` | :c:func:`PyDict_GetItemRef` |

_sources/library/asyncio-eventloop.rst.txt

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

598+
.. note::
599+
600+
On Windows, when using the proactor event loop with ``local_addr=None``,
601+
an :exc:`OSError` with :attr:`!errno.WSAEINVAL` will be raised
602+
when running it.
603+
598604
* *remote_addr*, if given, is a ``(remote_host, remote_port)`` tuple used
599605
to connect the socket to a remote address. The *remote_host* and
600606
*remote_port* are looked up using :meth:`getaddrinfo`.

_sources/library/asyncio-queue.rst.txt

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

_sources/library/codecs.rst.txt

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

14741474

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

14771507
Text Transforms

_sources/library/concurrent.futures.rst.txt

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

246+
Note that the restrictions on functions and arguments needing to picklable as
247+
per :class:`multiprocessing.Process` apply when using :meth:`~Executor.submit`
248+
and :meth:`~Executor.map` on a :class:`ProcessPoolExecutor`. A function defined
249+
in a REPL or a lambda should not be expected to work.
250+
246251
.. class:: ProcessPoolExecutor(max_workers=None, mp_context=None, initializer=None, initargs=(), max_tasks_per_child=None)
247252

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

_sources/library/enum.rst.txt

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,16 +504,31 @@ Data Types
504504

505505
.. class:: StrEnum
506506

507-
``StrEnum`` is the same as :class:`Enum`, but its members are also strings and can be used
508-
in most of the same places that a string can be used. The result of any string
509-
operation performed on or with a *StrEnum* member is not part of the enumeration.
507+
*StrEnum* is the same as :class:`Enum`, but its members are also strings and
508+
can be used in most of the same places that a string can be used. The result
509+
of any string operation performed on or with a *StrEnum* member is not part
510+
of the enumeration.
511+
512+
>>> from enum import StrEnum, auto
513+
>>> class Color(StrEnum):
514+
... RED = 'r'
515+
... GREEN = 'g'
516+
... BLUE = 'b'
517+
... UNKNOWN = auto()
518+
...
519+
>>> Color.RED
520+
<Color.RED: 'r'>
521+
>>> Color.UNKNOWN
522+
<Color.UNKNOWN: 'unknown'>
523+
>>> str(Color.UNKNOWN)
524+
'unknown'
510525

511526
.. note::
512527

513528
There are places in the stdlib that check for an exact :class:`str`
514529
instead of a :class:`str` subclass (i.e. ``type(unknown) == str``
515530
instead of ``isinstance(unknown, str)``), and in those locations you
516-
will need to use ``str(StrEnum.member)``.
531+
will need to use ``str(MyStrEnum.MY_MEMBER)``.
517532

518533
.. note::
519534

_sources/library/http.cookies.rst.txt

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

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

154157
The keys are case-insensitive and their default value is ``''``.
155158

_sources/library/importlib.resources.rst.txt

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

_sources/library/multiprocessing.rst.txt

Lines changed: 57 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:
@@ -107,6 +111,8 @@ Contexts and start methods
107111
Depending on the platform, :mod:`multiprocessing` supports three ways
108112
to start a process. These *start methods* are
109113

114+
.. _multiprocessing-start-method-spawn:
115+
110116
*spawn*
111117
The parent process starts a fresh Python interpreter process. The
112118
child process will only inherit those resources necessary to run
@@ -117,6 +123,8 @@ to start a process. These *start methods* are
117123

118124
Available on POSIX and Windows platforms. The default on Windows and macOS.
119125

126+
.. _multiprocessing-start-method-fork:
127+
120128
*fork*
121129
The parent process uses :func:`os.fork` to fork the Python
122130
interpreter. The child process, when it begins, is effectively
@@ -137,6 +145,8 @@ to start a process. These *start methods* are
137145
raise a :exc:`DeprecationWarning`. Use a different start method.
138146
See the :func:`os.fork` documentation for further explanation.
139147

148+
.. _multiprocessing-start-method-forkserver:
149+
140150
*forkserver*
141151
When the program starts and selects the *forkserver* start method,
142152
a server process is spawned. From then on, whenever a new process
@@ -218,9 +228,12 @@ processes for a different context. In particular, locks created using
218228
the *fork* context cannot be passed to processes started using the
219229
*spawn* or *forkserver* start methods.
220230

221-
A library which wants to use a particular start method should probably
222-
use :func:`get_context` to avoid interfering with the choice of the
223-
library user.
231+
Libraries using :mod:`multiprocessing` or
232+
:class:`~concurrent.futures.ProcessPoolExecutor` should be designed to allow
233+
their users to provide their own multiprocessing context. Using a specific
234+
context of your own within a library can lead to incompatibilities with the
235+
rest of the library user's application. Always document if your library
236+
requires a specific start method.
224237

225238
.. warning::
226239

@@ -518,9 +531,42 @@ The :mod:`multiprocessing` package mostly replicates the API of the
518531
to pass to *target*.
519532

520533
If a subclass overrides the constructor, it must make sure it invokes the
521-
base class constructor (:meth:`Process.__init__`) before doing anything else
534+
base class constructor (``super().__init__()``) before doing anything else
522535
to the process.
523536

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

@@ -2985,6 +3031,9 @@ Beware of replacing :data:`sys.stdin` with a "file like object"
29853031

29863032
For more information, see :issue:`5155`, :issue:`5313` and :issue:`5331`
29873033

3034+
.. _multiprocessing-programming-spawn:
3035+
.. _multiprocessing-programming-forkserver:
3036+
29883037
The *spawn* and *forkserver* start methods
29893038
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
29903039

@@ -2993,10 +3042,10 @@ start method.
29933042

29943043
More picklability
29953044

2996-
Ensure that all arguments to :meth:`Process.__init__` are picklable.
2997-
Also, if you subclass :class:`~multiprocessing.Process` then make sure that
2998-
instances will be picklable when the :meth:`Process.start
2999-
<multiprocessing.Process.start>` method is called.
3045+
Ensure that all arguments to :class:`~multiprocessing.Process` are
3046+
picklable. Also, if you subclass ``Process.__init__``, you must make sure
3047+
that instances will be picklable when the
3048+
:meth:`Process.start <multiprocessing.Process.start>` method is called.
30003049

30013050
Global variables
30023051

_sources/library/os.path.rst.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ the :mod:`glob` module.)
9494
Any iterable can now be passed, rather than just sequences.
9595

9696

97-
.. function:: commonprefix(list)
97+
.. function:: commonprefix(list, /)
9898

9999
Return the longest path prefix (taken character-by-character) that is a
100100
prefix of all paths in *list*. If *list* is empty, return the empty string
@@ -199,14 +199,14 @@ the :mod:`glob` module.)
199199
Accepts a :term:`path-like object`.
200200

201201

202-
.. function:: getatime(path)
202+
.. function:: getatime(path, /)
203203

204204
Return the time of last access of *path*. The return value is a floating-point number giving
205205
the number of seconds since the epoch (see the :mod:`time` module). Raise
206206
:exc:`OSError` if the file does not exist or is inaccessible.
207207

208208

209-
.. function:: getmtime(path)
209+
.. function:: getmtime(path, /)
210210

211211
Return the time of last modification of *path*. The return value is a floating-point number
212212
giving the number of seconds since the epoch (see the :mod:`time` module).
@@ -216,7 +216,7 @@ the :mod:`glob` module.)
216216
Accepts a :term:`path-like object`.
217217

218218

219-
.. function:: getctime(path)
219+
.. function:: getctime(path, /)
220220

221221
Return the system's ctime which, on some systems (like Unix) is the time of the
222222
last metadata change, and, on others (like Windows), is the creation time for *path*.
@@ -228,7 +228,7 @@ the :mod:`glob` module.)
228228
Accepts a :term:`path-like object`.
229229

230230

231-
.. function:: getsize(path)
231+
.. function:: getsize(path, /)
232232

233233
Return the size, in bytes, of *path*. Raise :exc:`OSError` if the file does
234234
not exist or is inaccessible.
@@ -351,7 +351,7 @@ the :mod:`glob` module.)
351351
.. versionadded:: 3.13
352352

353353

354-
.. function:: join(path, *paths)
354+
.. function:: join(path, /, *paths)
355355

356356
Join one or more path segments intelligently. The return value is the
357357
concatenation of *path* and all members of *\*paths*, with exactly one
@@ -402,7 +402,7 @@ the :mod:`glob` module.)
402402
Accepts a :term:`path-like object`.
403403

404404

405-
.. function:: realpath(path, *, strict=False)
405+
.. function:: realpath(path, /, *, strict=False)
406406

407407
Return the canonical path of the specified filename, eliminating any symbolic
408408
links encountered in the path (if they are supported by the operating
@@ -471,7 +471,7 @@ the :mod:`glob` module.)
471471
Accepts a :term:`path-like object`.
472472

473473

474-
.. function:: samefile(path1, path2)
474+
.. function:: samefile(path1, path2, /)
475475

476476
Return ``True`` if both pathname arguments refer to the same file or directory.
477477
This is determined by the device number and i-node number and raises an
@@ -498,7 +498,7 @@ the :mod:`glob` module.)
498498
Accepts a :term:`path-like object`.
499499

500500

501-
.. function:: samestat(stat1, stat2)
501+
.. function:: samestat(stat1, stat2, /)
502502

503503
Return ``True`` if the stat tuples *stat1* and *stat2* refer to the same file.
504504
These structures may have been returned by :func:`os.fstat`,

0 commit comments

Comments
 (0)