From 623c8cd8f41a99f22d39b264f7eaf7244417000b Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Tue, 4 May 2021 11:29:23 +0200 Subject: [PATCH] Refs #32074 -- Used asyncio.get_running_loop() instead of get_event_loop(). Using asyncio.get_event_loop() when there is no running event loop was deprecated in Python 3.10, see https://bugs.python.org/issue39529. --- django/utils/asyncio.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/django/utils/asyncio.py b/django/utils/asyncio.py index 2405e3413e1..285adbef8a9 100644 --- a/django/utils/asyncio.py +++ b/django/utils/asyncio.py @@ -16,12 +16,11 @@ def async_unsafe(message): if not os.environ.get('DJANGO_ALLOW_ASYNC_UNSAFE'): # Detect a running event loop in this thread. try: - event_loop = asyncio.get_event_loop() + asyncio.get_running_loop() except RuntimeError: pass else: - if event_loop.is_running(): - raise SynchronousOnlyOperation(message) + raise SynchronousOnlyOperation(message) # Pass onwards. return func(*args, **kwargs) return inner