mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
Replace Flask by Starlette
This commit is contained in:
parent
9667142d5c
commit
78561ce7bb
7 changed files with 1509 additions and 16 deletions
|
|
@ -226,18 +226,16 @@ def new_client(
|
|||
|
||||
def get_loop():
|
||||
global LOOP
|
||||
return LOOP
|
||||
if LOOP:
|
||||
return LOOP
|
||||
|
||||
loop_ready = threading.Lock()
|
||||
loop_ready.acquire()
|
||||
|
||||
def init():
|
||||
# log
|
||||
for logger_name in ('hpack.hpack', 'hpack.table'):
|
||||
logging.getLogger(logger_name).setLevel(logging.WARNING)
|
||||
|
||||
# loop
|
||||
def loop_thread():
|
||||
global LOOP
|
||||
LOOP = asyncio.new_event_loop()
|
||||
loop_ready.release()
|
||||
LOOP.run_forever()
|
||||
|
||||
thread = threading.Thread(
|
||||
|
|
@ -246,6 +244,5 @@ def init():
|
|||
daemon=True,
|
||||
)
|
||||
thread.start()
|
||||
|
||||
|
||||
init()
|
||||
loop_ready.acquire()
|
||||
return LOOP
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ from itertools import cycle
|
|||
import httpx
|
||||
|
||||
from .client import new_client, get_loop
|
||||
from searx import logger
|
||||
|
||||
|
||||
DEFAULT_NAME = '__DEFAULT__'
|
||||
|
|
@ -307,6 +308,8 @@ def done():
|
|||
future = asyncio.run_coroutine_threadsafe(Network.aclose_all(), loop)
|
||||
# wait 3 seconds to close the HTTP clients
|
||||
future.result(3)
|
||||
except:
|
||||
logger.exception('Exception while closing clients')
|
||||
finally:
|
||||
NETWORKS.clear()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue