diff options
author | Alexandre Flament <alex@al-f.net> | 2021-04-27 10:03:19 +0200 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarit.de> | 2021-04-27 17:47:36 +0200 |
commit | 283ae7bfad05fedbf6c7a7e7d7addfc3ae7ed9c7 (patch) | |
tree | b57413a1b766d08e6f40aebe2a166c564fa26213 /searx/network/__init__.py | |
parent | f724d6f6f1a38d11bc26c39648441bc8788b4288 (diff) | |
download | searxng-283ae7bfad05fedbf6c7a7e7d7addfc3ae7ed9c7.tar.gz searxng-283ae7bfad05fedbf6c7a7e7d7addfc3ae7ed9c7.zip |
[fix] searx.network: fix rare cases where LOOP is None
* searx.network.client.LOOP is initialized in a thread
* searx.network.__init__ imports LOOP which may happen
before the thread has initialized LOOP
This commit adds a new function "searx.network.client.get_loop()"
to fix this issue
Diffstat (limited to 'searx/network/__init__.py')
-rw-r--r-- | searx/network/__init__.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/searx/network/__init__.py b/searx/network/__init__.py index 40665f7d6..981b2261a 100644 --- a/searx/network/__init__.py +++ b/searx/network/__init__.py @@ -9,7 +9,7 @@ import httpx import h2.exceptions from .network import get_network, initialize -from .client import LOOP +from .client import get_loop from .raise_for_httperror import raise_for_httperror # queue.SimpleQueue: Support Python 3.6 @@ -98,7 +98,7 @@ def request(method, url, **kwargs): network = get_context_network() # do request - future = asyncio.run_coroutine_threadsafe(network.request(method, url, **kwargs), LOOP) + future = asyncio.run_coroutine_threadsafe(network.request(method, url, **kwargs), get_loop()) try: response = future.result(timeout) except concurrent.futures.TimeoutError as e: @@ -179,7 +179,7 @@ def stream(method, url, **kwargs): """ q = SimpleQueue() future = asyncio.run_coroutine_threadsafe(stream_chunk_to_queue(get_network(), q, method, url, **kwargs), - LOOP) + get_loop()) chunk_or_exception = q.get() while chunk_or_exception is not None: if isinstance(chunk_or_exception, Exception): |