Skip to content

Commit dcea78f

Browse files
bpo-42392: Mention loop removal in whatsnew for 3.10 (GH-24256)
@vstinner [noticed on python-dev](https://mail.python.org/archives/list/[email protected]/thread/O3T7SK3BGMFWMLCQXDODZJSBL42AUWTR/) that there is no what's new or porting entry for removal of asyncio ``loop`` parameter. This patch adds a basic guide. Co-Authored-By: Kyle Stanley <[email protected]>
1 parent a698d52 commit dcea78f

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

Doc/whatsnew/3.10.rst

+37
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,23 @@ Removed
558558
the :mod:`collections` module.
559559
(Contributed by Victor Stinner in :issue:`37324`.)
560560

561+
* The ``loop`` parameter has been removed from most of :mod:`asyncio`\ 's
562+
:doc:`high-level API <../library/asyncio-api-index>` following deprecation
563+
in Python 3.8. The motivation behind this change is multifold:
564+
565+
1. This simplifies the high-level API.
566+
2. The functions in the high-level API have been implicitly getting the
567+
current thread's running event loop since Python 3.7. There isn't a need to
568+
pass the event loop to the API in most normal use cases.
569+
3. Event loop passing is error-prone especially when dealing with loops
570+
running in different threads.
571+
572+
Note that the low-level API will still accept ``loop``.
573+
See `Changes in the Python API`_ for examples of how to replace existing code.
574+
575+
(Contributed by Yurii Karabas, Andrew Svetlov, Yury Selivanov and Kyle Stanley
576+
in :issue:`42392`.)
577+
561578

562579
Porting to Python 3.10
563580
======================
@@ -596,6 +613,26 @@ Changes in the Python API
596613
a 16-bit unsigned integer.
597614
(Contributed by Erlend E. Aasland in :issue:`42393`.)
598615

616+
* The ``loop`` parameter has been removed from most of :mod:`asyncio`\ 's
617+
:doc:`high-level API <../library/asyncio-api-index>` following deprecation
618+
in Python 3.8.
619+
620+
A coroutine that currently look like this::
621+
622+
async def foo(loop):
623+
await asyncio.sleep(1, loop=loop)
624+
625+
Should be replaced with this::
626+
627+
async def foo():
628+
await asyncio.sleep(1)
629+
630+
If ``foo()`` was specifically designed *not* to run in the current thread's
631+
running event loop (e.g. running in another thread's event loop), consider
632+
using :func:`asyncio.run_coroutine_threadsafe` instead.
633+
634+
(Contributed by Yurii Karabas, Andrew Svetlov, Yury Selivanov and Kyle Stanley
635+
in :issue:`42392`.)
599636

600637
CPython bytecode changes
601638
========================

0 commit comments

Comments
 (0)