From 283ae7bfad05fedbf6c7a7e7d7addfc3ae7ed9c7 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Tue, 27 Apr 2021 10:03:19 +0200 Subject: [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 --- searx/network/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'searx/network/__init__.py') 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): -- cgit v1.2.3