Skip to content

Commit 69fe4d7

Browse files
authored
Merge branch 'main' into deprecate-multi-loop-watcher
2 parents 821ccfc + b407312 commit 69fe4d7

File tree

158 files changed

+4378
-3770
lines changed

Some content is hidden

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

158 files changed

+4378
-3770
lines changed

.gitattributes

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,27 @@ PCbuild/readme.txt dos
6262
#
6363
[attr]generated linguist-generated=true diff=generated
6464

65-
**/clinic/*.c.h generated
66-
*_db.h generated
67-
Doc/data/stable_abi.dat generated
68-
Doc/library/token-list.inc generated
69-
Include/internal/pycore_ast.h generated
70-
Include/internal/pycore_ast_state.h generated
71-
Include/internal/pycore_opcode.h generated
72-
Include/opcode.h generated
73-
Include/token.h generated
74-
Lib/keyword.py generated
75-
Lib/test/test_stable_abi_ctypes.py generated
76-
Lib/token.py generated
77-
Objects/typeslots.inc generated
78-
PC/python3dll.c generated
79-
Parser/parser.c generated
80-
Parser/token.c generated
81-
Programs/test_frozenmain.h generated
82-
Python/Python-ast.c generated
83-
Python/opcode_targets.h generated
84-
Python/stdlib_module_names.h generated
85-
Tools/peg_generator/pegen/grammar_parser.py generated
86-
aclocal.m4 generated
87-
configure generated
65+
**/clinic/*.c.h generated
66+
*_db.h generated
67+
Doc/data/stable_abi.dat generated
68+
Doc/library/token-list.inc generated
69+
Include/internal/pycore_ast.h generated
70+
Include/internal/pycore_ast_state.h generated
71+
Include/internal/pycore_opcode.h generated
72+
Include/internal/pycore_runtime_init_generated.h generated
73+
Include/opcode.h generated
74+
Include/token.h generated
75+
Lib/keyword.py generated
76+
Lib/test/test_stable_abi_ctypes.py generated
77+
Lib/token.py generated
78+
Objects/typeslots.inc generated
79+
PC/python3dll.c generated
80+
Parser/parser.c generated
81+
Parser/token.c generated
82+
Programs/test_frozenmain.h generated
83+
Python/Python-ast.c generated
84+
Python/opcode_targets.h generated
85+
Python/stdlib_module_names.h generated
86+
Tools/peg_generator/pegen/grammar_parser.py generated
87+
aclocal.m4 generated
88+
configure generated

Doc/c-api/datetime.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,15 @@ Macros to create objects:
132132
resulting number of microseconds and seconds lie in the ranges documented for
133133
:class:`datetime.timedelta` objects.
134134
135+
135136
.. c:function:: PyObject* PyTimeZone_FromOffset(PyDateTime_DeltaType* offset)
136137
137138
Return a :class:`datetime.timezone` object with an unnamed fixed offset
138139
represented by the *offset* argument.
139140
140141
.. versionadded:: 3.7
141142
143+
142144
.. c:function:: PyObject* PyTimeZone_FromOffsetAndName(PyDateTime_DeltaType* offset, PyUnicode* name)
143145
144146
Return a :class:`datetime.timezone` object with a fixed offset represented
@@ -190,12 +192,21 @@ must not be ``NULL``, and the type is not checked:
190192
191193
Return the microsecond, as an int from 0 through 999999.
192194
195+
196+
.. c:function:: int PyDateTime_DATE_GET_FOLD(PyDateTime_DateTime *o)
197+
198+
Return the fold, as an int from 0 through 1.
199+
200+
.. versionadded:: 3.6
201+
202+
193203
.. c:function:: PyObject* PyDateTime_DATE_GET_TZINFO(PyDateTime_DateTime *o)
194204
195205
Return the tzinfo (which may be ``None``).
196206
197207
.. versionadded:: 3.10
198208
209+
199210
Macros to extract fields from time objects. The argument must be an instance of
200211
:c:data:`PyDateTime_Time`, including subclasses. The argument must not be ``NULL``,
201212
and the type is not checked:
@@ -219,6 +230,14 @@ and the type is not checked:
219230
220231
Return the microsecond, as an int from 0 through 999999.
221232
233+
234+
.. c:function:: int PyDateTime_TIME_GET_FOLD(PyDateTime_Time *o)
235+
236+
Return the fold, as an int from 0 through 1.
237+
238+
.. versionadded:: 3.6
239+
240+
222241
.. c:function:: PyObject* PyDateTime_TIME_GET_TZINFO(PyDateTime_Time *o)
223242
224243
Return the tzinfo (which may be ``None``).

Doc/howto/logging-cookbook.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ messages should not. Here's how you can achieve this::
219219
logging.basicConfig(level=logging.DEBUG,
220220
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
221221
datefmt='%m-%d %H:%M',
222-
filename='/temp/myapp.log',
222+
filename='/tmp/myapp.log',
223223
filemode='w')
224224
# define a Handler which writes INFO messages or higher to the sys.stderr
225225
console = logging.StreamHandler()
@@ -270,6 +270,11 @@ are sent to both destinations.
270270
This example uses console and file handlers, but you can use any number and
271271
combination of handlers you choose.
272272

273+
Note that the above choice of log filename ``/tmp/myapp.log`` implies use of a
274+
standard location for temporary files on POSIX systems. On Windows, you may need to
275+
choose a different directory name for the log - just ensure that the directory exists
276+
and that you have the permissions to create and update files in it.
277+
273278

274279
Configuration server example
275280
----------------------------

Doc/library/2to3.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. _2to3-reference:
22

3-
2to3 - Automated Python 2 to 3 code translation
4-
===============================================
3+
2to3 --- Automated Python 2 to 3 code translation
4+
=================================================
55

66
.. sectionauthor:: Benjamin Peterson <[email protected]>
77

@@ -456,8 +456,8 @@ and off individually. They are described here in more detail.
456456
``from future_builtins import zip`` appears.
457457
458458
459-
:mod:`lib2to3` - 2to3's library
460-
-------------------------------
459+
:mod:`lib2to3` --- 2to3's library
460+
---------------------------------
461461

462462
.. module:: lib2to3
463463
:synopsis: The 2to3 library

Doc/library/ast.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,10 +1028,11 @@ Control flow
10281028
.. class:: For(target, iter, body, orelse, type_comment)
10291029

10301030
A ``for`` loop. ``target`` holds the variable(s) the loop assigns to, as a
1031-
single :class:`Name`, :class:`Tuple` or :class:`List` node. ``iter`` holds
1032-
the item to be looped over, again as a single node. ``body`` and ``orelse``
1033-
contain lists of nodes to execute. Those in ``orelse`` are executed if the
1034-
loop finishes normally, rather than via a ``break`` statement.
1031+
single :class:`Name`, :class:`Tuple`, :class:`List`, :class:`Attribute` or
1032+
:class:`Subscript` node. ``iter`` holds the item to be looped over, again
1033+
as a single node. ``body`` and ``orelse`` contain lists of nodes to execute.
1034+
Those in ``orelse`` are executed if the loop finishes normally, rather than
1035+
via a ``break`` statement.
10351036

10361037
.. attribute:: type_comment
10371038

Doc/library/asyncio-task.rst

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,24 @@ Creating Tasks
282282
Added the *context* parameter.
283283

284284

285+
Task Cancellation
286+
=================
287+
288+
Tasks can easily and safely be cancelled.
289+
When a task is cancelled, :exc:`asyncio.CancelledError` will be raised
290+
in the task at the next opportunity.
291+
292+
It is recommended that coroutines use ``try/finally`` blocks to robustly
293+
perform clean-up logic. In case :exc:`asyncio.CancelledError`
294+
is explicitly caught, it should generally be propagated when
295+
clean-up is complete. Most code can safely ignore :exc:`asyncio.CancelledError`.
296+
297+
Important asyncio components, like :class:`asyncio.TaskGroup` and the
298+
:func:`asyncio.timeout` context manager, are implemented using cancellation
299+
internally and might misbehave if a coroutine swallows
300+
:exc:`asyncio.CancelledError`.
301+
302+
285303
Task Groups
286304
===========
287305

@@ -537,6 +555,122 @@ Shielding From Cancellation
537555
Timeouts
538556
========
539557

558+
.. coroutinefunction:: timeout(delay)
559+
560+
An :ref:`asynchronous context manager <async-context-managers>`
561+
that can be used to limit the amount of time spent waiting on
562+
something.
563+
564+
*delay* can either be ``None``, or a float/int number of
565+
seconds to wait. If *delay* is ``None``, no time limit will
566+
be applied; this can be useful if the delay is unknown when
567+
the context manager is created.
568+
569+
In either case, the context manager can be rescheduled after
570+
creation using :meth:`Timeout.reschedule`.
571+
572+
Example::
573+
574+
async def main():
575+
async with asyncio.timeout(10):
576+
await long_running_task()
577+
578+
If ``long_running_task`` takes more than 10 seconds to complete,
579+
the context manager will cancel the current task and handle
580+
the resulting :exc:`asyncio.CancelledError` internally, transforming it
581+
into an :exc:`asyncio.TimeoutError` which can be caught and handled.
582+
583+
.. note::
584+
585+
The :func:`asyncio.timeout` context manager is what transforms
586+
the :exc:`asyncio.CancelledError` into an :exc:`asyncio.TimeoutError`,
587+
which means the :exc:`asyncio.TimeoutError` can only be caught
588+
*outside* of the context manager.
589+
590+
Example of catching :exc:`asyncio.TimeoutError`::
591+
592+
async def main():
593+
try:
594+
async with asyncio.timeout(10):
595+
await long_running_task()
596+
except TimeoutError:
597+
print("The long operation timed out, but we've handled it.")
598+
599+
print("This statement will run regardless.")
600+
601+
The context manager produced by :func:`asyncio.timeout` can be
602+
rescheduled to a different deadline and inspected.
603+
604+
.. class:: Timeout()
605+
606+
An :ref:`asynchronous context manager <async-context-managers>`
607+
that limits time spent inside of it.
608+
609+
.. versionadded:: 3.11
610+
611+
.. method:: when() -> float | None
612+
613+
Return the current deadline, or ``None`` if the current
614+
deadline is not set.
615+
616+
The deadline is a float, consistent with the time returned by
617+
:meth:`loop.time`.
618+
619+
.. method:: reschedule(when: float | None)
620+
621+
Change the time the timeout will trigger.
622+
623+
If *when* is `None`, any current deadline will be removed, and the
624+
context manager will wait indefinitely.
625+
626+
If *when* is a float, it is set as the new deadline.
627+
628+
.. method:: expired() -> bool
629+
630+
Return whether the context manager has exceeded its deadline
631+
(expired).
632+
633+
Example::
634+
635+
async def main():
636+
try:
637+
# We do not know the timeout when starting, so we pass ``None``.
638+
async with asyncio.timeout(None) as cm:
639+
# We know the timeout now, so we reschedule it.
640+
new_deadline = get_running_loop().time() + 10
641+
cm.reschedule(new_deadline)
642+
643+
await long_running_task()
644+
except TimeoutError:
645+
pass
646+
647+
if cm.expired:
648+
print("Looks like we haven't finished on time.")
649+
650+
Timeout context managers can be safely nested.
651+
652+
.. versionadded:: 3.11
653+
654+
.. coroutinefunction:: timeout_at(when)
655+
656+
Similar to :func:`asyncio.timeout`, except *when* is the absolute time
657+
to stop waiting, or ``None``.
658+
659+
Example::
660+
661+
async def main():
662+
loop = get_running_loop()
663+
deadline = loop.time() + 20
664+
try:
665+
async with asyncio.timeout_at(deadline):
666+
await long_running_task()
667+
except TimeoutError:
668+
print("The long operation timed out, but we've handled it.")
669+
670+
print("This statement will run regardless.")
671+
672+
.. versionadded:: 3.11
673+
540674
.. coroutinefunction:: wait_for(aw, timeout)
541675

542676
Wait for the *aw* :ref:`awaitable <asyncio-awaitables>`

Doc/library/logging.handlers.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,8 @@ possible, while any potentially slow operations (such as sending an email via
10181018
have the task tracking API, which means that you can use
10191019
:class:`~queue.SimpleQueue` instances for *queue*.
10201020

1021+
.. note:: If you are using :mod:`multiprocessing`, you should avoid using
1022+
:class:`~queue.SimpleQueue` and instead use :class:`multiprocessing.Queue`.
10211023

10221024
.. method:: emit(record)
10231025

@@ -1091,6 +1093,9 @@ possible, while any potentially slow operations (such as sending an email via
10911093
task tracking API (though it's used if available), which means that you can
10921094
use :class:`~queue.SimpleQueue` instances for *queue*.
10931095

1096+
.. note:: If you are using :mod:`multiprocessing`, you should avoid using
1097+
:class:`~queue.SimpleQueue` and instead use :class:`multiprocessing.Queue`.
1098+
10941099
If ``respect_handler_level`` is ``True``, a handler's level is respected
10951100
(compared with the level for the message) when deciding whether to pass
10961101
messages to that handler; otherwise, the behaviour is as in previous Python

0 commit comments

Comments
 (0)