diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-10-05 12:39:13 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-05 12:39:13 +0200 |
| commit | 53fad80ffe16ab4edb713b1ef0090d0fcf63565a (patch) | |
| tree | 06a8c50ec7a348fe2c79a6d4aed3e9203f2f9b3e | |
| parent | f6726fdc3ec09d40fb53eef7ce9b6b5a05762548 (diff) | |
[3.2.x] Refs #32074 -- Used asyncio.get_running_loop() instead of get_event_loop() on Python 3.7+.
Using asyncio.get_event_loop() when there is no running event loop was
deprecated in Python 3.10, see https://bugs.python.org/issue39529.
| -rw-r--r-- | django/utils/asyncio.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/django/utils/asyncio.py b/django/utils/asyncio.py index 2405e3413e..cd4dcd9f46 100644 --- a/django/utils/asyncio.py +++ b/django/utils/asyncio.py @@ -3,6 +3,13 @@ import functools import os from django.core.exceptions import SynchronousOnlyOperation +from django.utils.version import PY37 + + +if PY37: + get_running_loop = asyncio.get_running_loop +else: + get_running_loop = asyncio.get_event_loop def async_unsafe(message): @@ -16,11 +23,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() + event_loop = get_running_loop() except RuntimeError: pass else: - if event_loop.is_running(): + if PY37 or event_loop.is_running(): raise SynchronousOnlyOperation(message) # Pass onwards. return func(*args, **kwargs) |
