mirror of https://github.com/searx/searx
Revert "[fix] searx.network: fix rare cases where LOOP is None"
This reverts commit 8d2ea790de
.
This commit is contained in:
parent
92d35faff9
commit
4b2ad032d3
|
@ -10,8 +10,13 @@ from types import MethodType
|
||||||
import httpx
|
import httpx
|
||||||
import h2.exceptions
|
import h2.exceptions
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
from .network import get_network, initialize, check_network_configuration
|
from .network import get_network, initialize, check_network_configuration
|
||||||
from .client import get_loop
|
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
|
from .raise_for_httperror import raise_for_httperror
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,7 +82,7 @@ def request(method, url, **kwargs):
|
||||||
network = get_context_network()
|
network = get_context_network()
|
||||||
|
|
||||||
# do request
|
# 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:
|
try:
|
||||||
response = future.result(timeout)
|
response = future.result(timeout)
|
||||||
except concurrent.futures.TimeoutError as e:
|
except concurrent.futures.TimeoutError as e:
|
||||||
|
@ -170,6 +175,7 @@ def stream(method, url, **kwargs):
|
||||||
"""
|
"""
|
||||||
q = SimpleQueue()
|
q = SimpleQueue()
|
||||||
future = asyncio.run_coroutine_threadsafe(stream_chunk_to_queue(get_network(), q, method, url, **kwargs),
|
future = asyncio.run_coroutine_threadsafe(stream_chunk_to_queue(get_network(), q, method, url, **kwargs),
|
||||||
|
<<<<<<< HEAD
|
||||||
get_loop())
|
get_loop())
|
||||||
# yield response
|
# yield response
|
||||||
response = q.get()
|
response = q.get()
|
||||||
|
@ -179,6 +185,9 @@ def stream(method, url, **kwargs):
|
||||||
yield response
|
yield response
|
||||||
|
|
||||||
# yield chunks
|
# yield chunks
|
||||||
|
=======
|
||||||
|
LOOP)
|
||||||
|
>>>>>>> parent of 8d2ea790 ([fix] searx.network: fix rare cases where LOOP is None)
|
||||||
chunk_or_exception = q.get()
|
chunk_or_exception = q.get()
|
||||||
while chunk_or_exception is not None:
|
while chunk_or_exception is not None:
|
||||||
if isinstance(chunk_or_exception, Exception):
|
if isinstance(chunk_or_exception, Exception):
|
||||||
|
|
|
@ -58,6 +58,7 @@ class AsyncProxyTransportFixed(AsyncProxyTransport):
|
||||||
|
|
||||||
|
|
||||||
def get_transport_for_socks_proxy(verify, http2, local_address, proxy_url, limit, retries):
|
def get_transport_for_socks_proxy(verify, http2, local_address, proxy_url, limit, retries):
|
||||||
|
global LOOP, TRANSPORT_KWARGS
|
||||||
# support socks5h (requests compatibility):
|
# support socks5h (requests compatibility):
|
||||||
# https://requests.readthedocs.io/en/master/user/advanced/#socks
|
# https://requests.readthedocs.io/en/master/user/advanced/#socks
|
||||||
# socks5:// hostname is resolved on client side
|
# 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)
|
return httpx.AsyncClient(transport=transport, mounts=mounts, max_redirects=max_redirects, event_hooks=event_hooks)
|
||||||
|
|
||||||
|
|
||||||
def get_loop():
|
|
||||||
global LOOP
|
|
||||||
return LOOP
|
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
# log
|
# log
|
||||||
for logger_name in ('hpack.hpack', 'hpack.table'):
|
for logger_name in ('hpack.hpack', 'hpack.table'):
|
||||||
|
|
|
@ -390,9 +390,8 @@ def done():
|
||||||
So Network.aclose is called here using atexit.register
|
So Network.aclose is called here using atexit.register
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
loop = get_loop()
|
if LOOP:
|
||||||
if loop:
|
future = asyncio.run_coroutine_threadsafe(Network.aclose_all(), LOOP)
|
||||||
future = asyncio.run_coroutine_threadsafe(Network.aclose_all(), loop)
|
|
||||||
# wait 3 seconds to close the HTTP clients
|
# wait 3 seconds to close the HTTP clients
|
||||||
future.result(3)
|
future.result(3)
|
||||||
finally:
|
finally:
|
||||||
|
|
Loading…
Reference in New Issue