bpo-39529: Deprecate creating new event loop in asyncio.get_event_loop() (GH-23554)
asyncio.get_event_loop() emits now a deprecation warning when it creates a new event loop.
In future releases it will became an alias of asyncio.get_running_loop().
diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst
index 7de5a0a..ca91efe 100644
--- a/Doc/library/asyncio-eventloop.rst
+++ b/Doc/library/asyncio-eventloop.rst
@@ -53,6 +53,11 @@
Consider also using the :func:`asyncio.run` function instead of using
lower level functions to manually create and close an event loop.
+ .. deprecated:: 3.10
+ Deprecation warning is emitted if there is no running event loop.
+ If future Python releases this function will be an alias of
+ :func:`get_running_loop`.
+
.. function:: set_event_loop(loop)
Set *loop* as a current event loop for the current OS thread.
diff --git a/Doc/library/asyncio-future.rst b/Doc/library/asyncio-future.rst
index 939d4c1..ef496a2 100644
--- a/Doc/library/asyncio-future.rst
+++ b/Doc/library/asyncio-future.rst
@@ -57,12 +57,20 @@
.. versionchanged:: 3.5.1
The function accepts any :term:`awaitable` object.
+ .. deprecated:: 3.10
+ Deprecation warning is emitted if *obj* is not a Future-like object
+ and *loop* is not specified and there is no running event loop.
+
.. function:: wrap_future(future, *, loop=None)
Wrap a :class:`concurrent.futures.Future` object in a
:class:`asyncio.Future` object.
+ .. deprecated:: 3.10
+ Deprecation warning is emitted if *future* is not a Future-like object
+ and *loop* is not specified and there is no running event loop.
+
Future Object
=============
@@ -90,6 +98,10 @@
.. versionchanged:: 3.7
Added support for the :mod:`contextvars` module.
+ .. deprecated:: 3.10
+ Deprecation warning is emitted if *loop* is not specified
+ and there is no running event loop.
+
.. method:: result()
Return the result of the Future.
diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst
index 1ca1b4a..3f54ecb 100644
--- a/Doc/library/asyncio-task.rst
+++ b/Doc/library/asyncio-task.rst
@@ -397,6 +397,11 @@
If the *gather* itself is cancelled, the cancellation is
propagated regardless of *return_exceptions*.
+ .. deprecated:: 3.10
+ Deprecation warning is emitted if no positional arguments are provided
+ or not all positional arguments are Future-like objects
+ and there is no running event loop.
+
Shielding From Cancellation
===========================
@@ -434,6 +439,10 @@
except CancelledError:
res = None
+ .. deprecated:: 3.10
+ Deprecation warning is emitted if *aw* is not Future-like object
+ and there is no running event loop.
+
Timeouts
========
@@ -593,6 +602,10 @@
earliest_result = await coro
# ...
+ .. deprecated:: 3.10
+ Deprecation warning is emitted if not all awaitable objects in the *aws*
+ iterable are Future-like objects and there is no running event loop.
+
Running in Threads
==================
@@ -775,6 +788,10 @@
.. deprecated-removed:: 3.8 3.10
The *loop* parameter.
+ .. deprecated:: 3.10
+ Deprecation warning is emitted if *loop* is not specified
+ and there is no running event loop.
+
.. method:: cancel(msg=None)
Request the Task to be cancelled.