mirror of
https://github.com/searxng/searxng.git
synced 2025-12-22 19:50:00 +00:00
[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
This commit is contained in:
committed by
Markus Heiser
parent
f724d6f6f1
commit
283ae7bfad
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user