summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorŁukasz Langa <lukasz@langa.pl>2022-12-06 17:40:30 (GMT)
committerGitHub <noreply@github.com>2022-12-06 17:40:30 (GMT)
commit300d812fd1c4d9244e71de0d228cc72439d312a7 (patch)
treeaa1099bf0884e6f4ad885825e7b8132da133b1a7 /Lib/asyncio
parentb7ae1d22857c141ea4b0cc1f107e128596d02a94 (diff)
downloadcpython-300d812fd1c4d9244e71de0d228cc72439d312a7.zip
cpython-300d812fd1c4d9244e71de0d228cc72439d312a7.tar.gz
cpython-300d812fd1c4d9244e71de0d228cc72439d312a7.tar.bz2
[3.10] gh-93453: Only emit deprecation warning in asyncio.get_event_loop when a new event loop is created (#100059)
It no longer emits a deprecation warning if the current event loop was set. (cherry picked from commit 3fae04b10e2655a20a3aadb5e0d63e87206d0c67) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/events.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py
index 5ab1acc..faac537 100644
--- a/Lib/asyncio/events.py
+++ b/Lib/asyncio/events.py
@@ -650,6 +650,21 @@ class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy):
if (self._local._loop is None and
not self._local._set_called and
threading.current_thread() is threading.main_thread()):
+ stacklevel = 2
+ try:
+ f = sys._getframe(1)
+ except AttributeError:
+ pass
+ else:
+ while f:
+ module = f.f_globals.get('__name__')
+ if not (module == 'asyncio' or module.startswith('asyncio.')):
+ break
+ f = f.f_back
+ stacklevel += 1
+ import warnings
+ warnings.warn('There is no current event loop',
+ DeprecationWarning, stacklevel=stacklevel)
self.set_event_loop(self.new_event_loop())
if self._local._loop is None:
@@ -763,12 +778,13 @@ def get_event_loop():
def _get_event_loop(stacklevel=3):
+ # This internal method is going away in Python 3.12, left here only for
+ # backwards compatibility with 3.10.0 - 3.10.8 and 3.11.0.
+ # Similarly, this method's C equivalent in _asyncio is going away as well.
+ # See GH-99949 for more details.
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()