summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/events.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2021-04-25 10:40:44 (GMT)
committerGitHub <noreply@github.com>2021-04-25 10:40:44 (GMT)
commit172c0f2752d8708b6dda7b42e6c5a3519420a4e8 (patch)
tree35a076c6baad7ca053a62b9f505af3762a867b79 /Lib/asyncio/events.py
parentface87c94e67ad9c72b9a3724f112fd76c1002b9 (diff)
downloadcpython-172c0f2752d8708b6dda7b42e6c5a3519420a4e8.zip
cpython-172c0f2752d8708b6dda7b42e6c5a3519420a4e8.tar.gz
cpython-172c0f2752d8708b6dda7b42e6c5a3519420a4e8.tar.bz2
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().
Diffstat (limited to 'Lib/asyncio/events.py')
-rw-r--r--Lib/asyncio/events.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py
index 1a20f36..b966ad2 100644
--- a/Lib/asyncio/events.py
+++ b/Lib/asyncio/events.py
@@ -759,9 +759,16 @@ def get_event_loop():
the result of `get_event_loop_policy().get_event_loop()` call.
"""
# NOTE: this function is implemented in C (see _asynciomodule.c)
+ return _py__get_event_loop()
+
+
+def _get_event_loop(stacklevel=3):
current_loop = _get_running_loop()
if current_loop is not None:
return current_loop
+ import warnings
+ warnings.warn('There is no current event loop',
+ DeprecationWarning, stacklevel=stacklevel)
return get_event_loop_policy().get_event_loop()
@@ -791,6 +798,7 @@ _py__get_running_loop = _get_running_loop
_py__set_running_loop = _set_running_loop
_py_get_running_loop = get_running_loop
_py_get_event_loop = get_event_loop
+_py__get_event_loop = _get_event_loop
try:
@@ -798,7 +806,7 @@ try:
# functions in asyncio. Pure Python implementation is
# about 4 times slower than C-accelerated.
from _asyncio import (_get_running_loop, _set_running_loop,
- get_running_loop, get_event_loop)
+ get_running_loop, get_event_loop, _get_event_loop)
except ImportError:
pass
else:
@@ -807,3 +815,4 @@ else:
_c__set_running_loop = _set_running_loop
_c_get_running_loop = get_running_loop
_c_get_event_loop = get_event_loop
+ _c__get_event_loop = _get_event_loop