summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2022-12-06 15:15:44 (GMT)
committerGitHub <noreply@github.com>2022-12-06 15:15:44 (GMT)
commit3fae04b10e2655a20a3aadb5e0d63e87206d0c67 (patch)
tree421cb42ccdc341c9a9cb52796b47b4942084e167 /Lib/asyncio
parent235f5fd2ca4c6acb4b04efeaaa1ecb46d41d5a6d (diff)
downloadcpython-3fae04b10e2655a20a3aadb5e0d63e87206d0c67.zip
cpython-3fae04b10e2655a20a3aadb5e0d63e87206d0c67.tar.gz
cpython-3fae04b10e2655a20a3aadb5e0d63e87206d0c67.tar.bz2
[3.11] gh-93453: Only emit deprecation warning in asyncio.get_event_loop when a new event loop is created (#99949)
It no longer emits a deprecation warning if the current event loop was set. 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 0d26ea5..af3f9e9 100644
--- a/Lib/asyncio/events.py
+++ b/Lib/asyncio/events.py
@@ -671,6 +671,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:
@@ -786,12 +801,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()