Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:trenn:python:django3_2
python-asgiref
fix_get_running_loop_before_python_3_7.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File fix_get_running_loop_before_python_3_7.patch of Package python-asgiref
Workaround to fix non existing get_running_loop before python 3.7 Found here: https://github.com/dask/distributed/issues/3381 (by trenn@suse.de) Index: asgiref-3.5.2/asgiref/sync.py =================================================================== --- asgiref-3.5.2.orig/asgiref/sync.py +++ asgiref-3.5.2/asgiref/sync.py @@ -1,10 +1,16 @@ +import sys + +if sys.version_info[:2] >= (3, 7): + from asyncio import get_running_loop +else: + from asyncio import _get_running_loop as get_running_loop + import asyncio import asyncio.coroutines import contextvars import functools import inspect import os -import sys import threading import warnings import weakref @@ -128,7 +134,7 @@ class AsyncToSync: self.main_event_loop = None else: try: - self.main_event_loop = asyncio.get_running_loop() + self.main_event_loop = get_running_loop() except RuntimeError: # There's no event loop in this thread. Look for the threadlocal if # we're inside SyncToAsync @@ -147,7 +153,7 @@ class AsyncToSync: def __call__(self, *args, **kwargs): # You can't call AsyncToSync from a thread with a running event loop try: - event_loop = asyncio.get_running_loop() + event_loop = get_running_loop() except RuntimeError: pass else: @@ -375,7 +381,7 @@ class SyncToAsync: pass async def __call__(self, *args, **kwargs): - loop = asyncio.get_running_loop() + loop = get_running_loop() # Work out what thread to run the code in if self._thread_sensitive: Index: asgiref-3.5.2/tests/test_sync.py =================================================================== --- asgiref-3.5.2.orig/tests/test_sync.py +++ asgiref-3.5.2/tests/test_sync.py @@ -1,4 +1,10 @@ -import asyncio +import sys + +if sys.version_info[:2] >= (3, 7): + from asyncio import get_running_loop +else: + from asyncio import _get_running_loop as get_running_loop + import functools import multiprocessing import threading @@ -35,7 +41,7 @@ async def test_sync_to_async(): assert result == 42 assert end - start >= 1 # Set workers to 1, call it twice and make sure that works right - loop = asyncio.get_running_loop() + loop = get_running_loop() old_executor = loop._default_executor or ThreadPoolExecutor() loop.set_default_executor(ThreadPoolExecutor(max_workers=1)) try:
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor