Skip to content

Commit 49f3393

Browse files
Merge branch 'main' of https://github.com/python/cpython into asyncio-tsafe
2 parents 195c87d + b2ac70a commit 49f3393

File tree

68 files changed

+1343
-835
lines changed

Some content is hidden

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

68 files changed

+1343
-835
lines changed

Doc/c-api/object.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ Object Protocol
111111
.. note::
112112
113113
Exceptions that occur when this calls :meth:`~object.__getattr__` and
114-
:meth:`~object.__getattribute__` methods are silently ignored.
114+
:meth:`~object.__getattribute__` methods aren't propagated,
115+
but instead given to :func:`sys.unraisablehook`.
115116
For proper error handling, use :c:func:`PyObject_HasAttrWithError`,
116117
:c:func:`PyObject_GetOptionalAttr` or :c:func:`PyObject_GetAttr` instead.
117118

Doc/c-api/typeobj.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
10231023
:c:macro:`Py_TPFLAGS_HAVE_GC` flag bit is clear in the subtype and the
10241024
:c:member:`~PyTypeObject.tp_traverse` and :c:member:`~PyTypeObject.tp_clear` fields in the subtype exist and have
10251025
``NULL`` values.
1026+
10261027
.. XXX are most flag bits *really* inherited individually?
10271028
10281029
**Default:**

Doc/deprecations/pending-removal-in-3.16.rst

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,35 @@ Pending removal in Python 3.16
1919
* :mod:`asyncio`:
2020

2121
* :func:`!asyncio.iscoroutinefunction` is deprecated
22-
and will be removed in Python 3.16,
22+
and will be removed in Python 3.16;
2323
use :func:`inspect.iscoroutinefunction` instead.
2424
(Contributed by Jiahao Li and Kumar Aditya in :gh:`122875`.)
2525

26+
* :mod:`asyncio` policy system is deprecated and will be removed in Python 3.16.
27+
In particular, the following classes and functions are deprecated:
28+
29+
* :class:`asyncio.AbstractEventLoopPolicy`
30+
* :class:`asyncio.DefaultEventLoopPolicy`
31+
* :class:`asyncio.WindowsSelectorEventLoopPolicy`
32+
* :class:`asyncio.WindowsProactorEventLoopPolicy`
33+
* :func:`asyncio.get_event_loop_policy`
34+
* :func:`asyncio.set_event_loop_policy`
35+
* :func:`asyncio.set_event_loop`
36+
37+
Users should use :func:`asyncio.run` or :class:`asyncio.Runner` with
38+
*loop_factory* to use the desired event loop implementation.
39+
40+
For example, to use :class:`asyncio.SelectorEventLoop` on Windows::
41+
42+
import asyncio
43+
44+
async def main():
45+
...
46+
47+
asyncio.run(main(), loop_factory=asyncio.SelectorEventLoop)
48+
49+
(Contributed by Kumar Aditya in :gh:`127949`.)
50+
2651
* :mod:`builtins`:
2752

2853
* Bitwise inversion on boolean types, ``~True`` or ``~False``

Doc/library/asyncio-eventloop.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ an event loop:
6262
.. versionchanged:: 3.14
6363
Raises a :exc:`RuntimeError` if there is no current event loop.
6464

65+
.. note::
66+
67+
The :mod:`!asyncio` policy system is deprecated and will be removed
68+
in Python 3.16; from there on, this function will always return the
69+
running event loop.
70+
71+
6572
.. function:: set_event_loop(loop)
6673

6774
Set *loop* as the current event loop for the current OS thread.
@@ -1781,12 +1788,11 @@ By default asyncio is configured to use :class:`EventLoop`.
17811788
import asyncio
17821789
import selectors
17831790

1784-
class MyPolicy(asyncio.DefaultEventLoopPolicy):
1785-
def new_event_loop(self):
1786-
selector = selectors.SelectSelector()
1787-
return asyncio.SelectorEventLoop(selector)
1791+
async def main():
1792+
...
17881793

1789-
asyncio.set_event_loop_policy(MyPolicy())
1794+
loop_factory = lambda: asyncio.SelectorEventLoop(selectors.SelectSelector())
1795+
asyncio.run(main(), loop_factory=loop_factory)
17901796

17911797

17921798
.. availability:: Unix, Windows.

Doc/library/asyncio-policy.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
Policies
88
========
99

10+
.. warning::
11+
12+
Policies are deprecated and will be removed in Python 3.16.
13+
Users are encouraged to use the :func:`asyncio.run` function
14+
or the :class:`asyncio.Runner` with *loop_factory* to use
15+
the desired loop implementation.
16+
17+
1018
An event loop policy is a global object
1119
used to get and set the current :ref:`event loop <asyncio-event-loop>`,
1220
as well as create new event loops.

Doc/library/asyncio-runner.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ Running an asyncio Program
7676

7777
*coro* can be any awaitable object.
7878

79+
.. note::
80+
81+
The :mod:`!asyncio` policy system is deprecated and will be removed
82+
in Python 3.16; from there on, an explicit *loop_factory* is needed
83+
to configure the event loop.
84+
7985

8086
Runner context manager
8187
======================

Doc/library/asyncio-task.rst

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,14 +1067,59 @@ Scheduling From Other Threads
10671067
This function is meant to be called from a different OS thread
10681068
than the one where the event loop is running. Example::
10691069

1070-
# Create a coroutine
1071-
coro = asyncio.sleep(1, result=3)
1072-
1073-
# Submit the coroutine to a given loop
1074-
future = asyncio.run_coroutine_threadsafe(coro, loop)
1075-
1076-
# Wait for the result with an optional timeout argument
1077-
assert future.result(timeout) == 3
1070+
def in_thread(loop: asyncio.AbstractEventLoop) -> None:
1071+
# Run some blocking IO
1072+
pathlib.Path("example.txt").write_text("hello world", encoding="utf8")
1073+
1074+
# Create a coroutine
1075+
coro = asyncio.sleep(1, result=3)
1076+
1077+
# Submit the coroutine to a given loop
1078+
future = asyncio.run_coroutine_threadsafe(coro, loop)
1079+
1080+
# Wait for the result with an optional timeout argument
1081+
assert future.result(timeout=2) == 3
1082+
1083+
async def amain() -> None:
1084+
# Get the running loop
1085+
loop = asyncio.get_running_loop()
1086+
1087+
# Run something in a thread
1088+
await asyncio.to_thread(in_thread, loop)
1089+
1090+
It's also possible to run the other way around. Example::
1091+
1092+
@contextlib.contextmanager
1093+
def loop_in_thread() -> Generator[asyncio.AbstractEventLoop]:
1094+
loop_fut = concurrent.futures.Future[asyncio.AbstractEventLoop]()
1095+
stop_event = asyncio.Event()
1096+
1097+
async def main() -> None:
1098+
loop_fut.set_result(asyncio.get_running_loop())
1099+
await stop_event.wait()
1100+
1101+
with concurrent.futures.ThreadPoolExecutor(1) as tpe:
1102+
complete_fut = tpe.submit(asyncio.run, main())
1103+
for fut in concurrent.futures.as_completed((loop_fut, complete_fut)):
1104+
if fut is loop_fut:
1105+
loop = loop_fut.result()
1106+
try:
1107+
yield loop
1108+
finally:
1109+
loop.call_soon_threadsafe(stop_event.set)
1110+
else:
1111+
fut.result()
1112+
1113+
# Create a loop in another thread
1114+
with loop_in_thread() as loop:
1115+
# Create a coroutine
1116+
coro = asyncio.sleep(1, result=3)
1117+
1118+
# Submit the coroutine to a given loop
1119+
future = asyncio.run_coroutine_threadsafe(coro, loop)
1120+
1121+
# Wait for the result with an optional timeout argument
1122+
assert future.result(timeout=2) == 3
10781123

10791124
If an exception is raised in the coroutine, the returned Future
10801125
will be notified. It can also be used to cancel the task in

Doc/library/calendar.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is
138138

139139
:class:`TextCalendar` instances have the following methods:
140140

141+
.. method:: formatweek(theweek, w=0)
142+
143+
Return a single week in a string with no newline. If *w* is provided, it
144+
specifies the width of the date columns, which are centered. Depends
145+
on the first weekday as specified in the constructor or set by the
146+
:meth:`setfirstweekday` method.
147+
148+
141149
.. method:: formatmonth(theyear, themonth, w=0, l=0)
142150

143151
Return a month's calendar in a multi-line string. If *w* is provided, it

Doc/library/socket.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,14 @@ Constants
674674

675675
.. availability:: Linux >= 3.9
676676

677+
.. data:: SO_REUSEPORT_LB
678+
679+
Constant to enable duplicate address and port bindings with load balancing.
680+
681+
.. versionadded:: next
682+
683+
.. availability:: FreeBSD >= 12.0
684+
677685
.. data:: AF_HYPERV
678686
HV_PROTOCOL_RAW
679687
HVSOCKET_CONNECT_TIMEOUT

Doc/library/urllib.request.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ The following classes are provided:
411411
:ref:`http-password-mgr` for information on the interface that must be
412412
supported.
413413

414+
.. versionchanged:: 3.14
415+
Added support for HTTP digest authentication algorithm ``SHA-256``.
416+
414417

415418
.. class:: HTTPDigestAuthHandler(password_mgr=None)
416419

0 commit comments

Comments
 (0)