mirror of
https://github.com/searxng/searxng.git
synced 2025-07-13 16:29:17 +02: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:
parent
f724d6f6f1
commit
283ae7bfad
3 changed files with 13 additions and 8 deletions
|
@ -7,7 +7,7 @@ from itertools import cycle
|
|||
|
||||
import httpx
|
||||
|
||||
from .client import new_client, LOOP
|
||||
from .client import new_client, get_loop
|
||||
|
||||
|
||||
DEFAULT_NAME = '__DEFAULT__'
|
||||
|
@ -291,8 +291,9 @@ def done():
|
|||
So Network.aclose is called here using atexit.register
|
||||
"""
|
||||
try:
|
||||
if LOOP:
|
||||
future = asyncio.run_coroutine_threadsafe(Network.aclose_all(), LOOP)
|
||||
loop = get_loop()
|
||||
if loop:
|
||||
future = asyncio.run_coroutine_threadsafe(Network.aclose_all(), loop)
|
||||
# wait 3 seconds to close the HTTP clients
|
||||
future.result(3)
|
||||
finally:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue