Revert "[fix] searx.network: fix rare cases where LOOP is None"

This reverts commit 8d2ea790de.
This commit is contained in:
Noémi Ványi 2022-07-30 16:37:25 +02:00
parent 92d35faff9
commit 4b2ad032d3
3 changed files with 13 additions and 9 deletions

View File

@ -10,8 +10,13 @@ from types import MethodType
import httpx
import h2.exceptions
<<<<<<< HEAD
from .network import get_network, initialize, check_network_configuration
from .client import get_loop
=======
from .network import get_network, initialize
from .client import LOOP
>>>>>>> parent of 8d2ea790 ([fix] searx.network: fix rare cases where LOOP is None)
from .raise_for_httperror import raise_for_httperror
@ -77,7 +82,7 @@ def request(method, url, **kwargs):
network = get_context_network()
# do request
future = asyncio.run_coroutine_threadsafe(network.request(method, url, **kwargs), get_loop())
future = asyncio.run_coroutine_threadsafe(network.request(method, url, **kwargs), LOOP)
try:
response = future.result(timeout)
except concurrent.futures.TimeoutError as e:
@ -170,6 +175,7 @@ def stream(method, url, **kwargs):
"""
q = SimpleQueue()
future = asyncio.run_coroutine_threadsafe(stream_chunk_to_queue(get_network(), q, method, url, **kwargs),
<<<<<<< HEAD
get_loop())
# yield response
response = q.get()
@ -179,6 +185,9 @@ def stream(method, url, **kwargs):
yield response
# yield chunks
=======
LOOP)
>>>>>>> parent of 8d2ea790 ([fix] searx.network: fix rare cases where LOOP is None)
chunk_or_exception = q.get()
while chunk_or_exception is not None:
if isinstance(chunk_or_exception, Exception):

View File

@ -58,6 +58,7 @@ class AsyncProxyTransportFixed(AsyncProxyTransport):
def get_transport_for_socks_proxy(verify, http2, local_address, proxy_url, limit, retries):
global LOOP, TRANSPORT_KWARGS
# support socks5h (requests compatibility):
# https://requests.readthedocs.io/en/master/user/advanced/#socks
# socks5:// hostname is resolved on client side
@ -139,11 +140,6 @@ def new_client(enable_http, verify, enable_http2,
return httpx.AsyncClient(transport=transport, mounts=mounts, max_redirects=max_redirects, event_hooks=event_hooks)
def get_loop():
global LOOP
return LOOP
def init():
# log
for logger_name in ('hpack.hpack', 'hpack.table'):

View File

@ -390,9 +390,8 @@ def done():
So Network.aclose is called here using atexit.register
"""
try:
loop = get_loop()
if loop:
future = asyncio.run_coroutine_threadsafe(Network.aclose_all(), loop)
if LOOP:
future = asyncio.run_coroutine_threadsafe(Network.aclose_all(), LOOP)
# wait 3 seconds to close the HTTP clients
future.result(3)
finally: