From cfa74fc4c1442c73d23e1822e02bd5ee5b4878b8 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Fri, 27 Dec 2024 13:40:06 +0000 Subject: [PATCH 1/3] make deprecation of policy system more prominent --- Doc/deprecations/pending-removal-in-3.16.rst | 27 +++++++++++++++++++- Doc/library/asyncio-eventloop.rst | 14 ++++++---- Doc/library/asyncio-runner.rst | 4 +++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/Doc/deprecations/pending-removal-in-3.16.rst b/Doc/deprecations/pending-removal-in-3.16.rst index 6f6954b783a1ae..f2b818f14c63cd 100644 --- a/Doc/deprecations/pending-removal-in-3.16.rst +++ b/Doc/deprecations/pending-removal-in-3.16.rst @@ -19,10 +19,35 @@ Pending removal in Python 3.16 * :mod:`asyncio`: * :func:`!asyncio.iscoroutinefunction` is deprecated - and will be removed in Python 3.16, + and will be removed in Python 3.16; use :func:`inspect.iscoroutinefunction` instead. (Contributed by Jiahao Li and Kumar Aditya in :gh:`122875`.) + * :mod:`asyncio` policy system is deprecated and will be removed in Python 3.16. + In particular, the following classes and functions are deprecated: + + * :class:`asyncio.AbstractEventLoopPolicy` + * :class:`asyncio.DefaultEventLoopPolicy` + * :class:`asyncio.WindowsSelectorEventLoopPolicy` + * :class:`asyncio.WindowsProactorEventLoopPolicy` + * :func:`asyncio.get_event_loop_policy` + * :func:`asyncio.set_event_loop_policy` + * :func:`asyncio.set_event_loop` + + Users should use :func:`asyncio.run` or :class:`asyncio.Runner` with + *loop_factory* to use the desired event loop implementation. + + For example, to use :class:`asyncio.SelectorEventLoop` on Windows:: + + import asyncio + + async def main(): + ... + + asyncio.run(main(), loop_factory=asyncio.SelectorEventLoop) + + (Contributed by Kumar Aditya in :gh:`127949`.) + * :mod:`builtins`: * Bitwise inversion on boolean types, ``~True`` or ``~False`` diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst index 29f843123f8560..a164e3a03a7e0b 100644 --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -62,6 +62,11 @@ an event loop: .. versionchanged:: 3.14 Raises a :exc:`RuntimeError` if there is no current event loop. + .. note:: + asyncio policy system is deprecated and will be removed in Python 3.16 + as such in future this function will always return the running event loop. + + .. function:: set_event_loop(loop) Set *loop* as the current event loop for the current OS thread. @@ -1781,12 +1786,11 @@ By default asyncio is configured to use :class:`EventLoop`. import asyncio import selectors - class MyPolicy(asyncio.DefaultEventLoopPolicy): - def new_event_loop(self): - selector = selectors.SelectSelector() - return asyncio.SelectorEventLoop(selector) + async def main(): + ... - asyncio.set_event_loop_policy(MyPolicy()) + loop_factory = lambda: asyncio.SelectorEventLoop(selectors.SelectSelector()) + asyncio.run(main(), loop_factory=loop_factory) .. availability:: Unix, Windows. diff --git a/Doc/library/asyncio-runner.rst b/Doc/library/asyncio-runner.rst index 28d5aaf3692baa..5a3e3881a479aa 100644 --- a/Doc/library/asyncio-runner.rst +++ b/Doc/library/asyncio-runner.rst @@ -76,6 +76,10 @@ Running an asyncio Program *coro* can be any awaitable object. + .. note:: + asyncio policy system is deprecated and will be removed in Python 3.16 + as such in future *loop_factory* must be used to configure the event loop. + Runner context manager ====================== From 33a2d64596fca12618d7805676b6eb3da3c9a4a5 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Fri, 27 Dec 2024 20:38:20 +0530 Subject: [PATCH 2/3] Update Doc/library/asyncio-runner.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Doc/library/asyncio-runner.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Doc/library/asyncio-runner.rst b/Doc/library/asyncio-runner.rst index 5a3e3881a479aa..48d78099fd3ce7 100644 --- a/Doc/library/asyncio-runner.rst +++ b/Doc/library/asyncio-runner.rst @@ -77,8 +77,10 @@ Running an asyncio Program *coro* can be any awaitable object. .. note:: - asyncio policy system is deprecated and will be removed in Python 3.16 - as such in future *loop_factory* must be used to configure the event loop. + + The :mod:`!asyncio` policy system is deprecated and will be removed + in Python 3.16; from there on, an explicit *loop_factory* is needed + to configure the event loop. Runner context manager From a990e742cef97c1bd432f4c7caed18c68b675f7e Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Fri, 27 Dec 2024 20:38:52 +0530 Subject: [PATCH 3/3] Update Doc/library/asyncio-eventloop.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Doc/library/asyncio-eventloop.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst index a164e3a03a7e0b..ccb362d8c31ddf 100644 --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -63,8 +63,10 @@ an event loop: Raises a :exc:`RuntimeError` if there is no current event loop. .. note:: - asyncio policy system is deprecated and will be removed in Python 3.16 - as such in future this function will always return the running event loop. + + The :mod:`!asyncio` policy system is deprecated and will be removed + in Python 3.16; from there on, this function will always return the + running event loop. .. function:: set_event_loop(loop)