mirror of
https://github.com/theroyallab/tabbyAPI.git
synced 2026-04-28 02:01:24 +00:00
Signals: Split signal handler between sync and async
Asyncio requires a closure of the event loop while sync can use SystemExit to kill the program. Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
@@ -22,11 +22,20 @@ def signal_handler(*_):
|
|||||||
SHUTTING_DOWN = True
|
SHUTTING_DOWN = True
|
||||||
|
|
||||||
# Run async unloads for model
|
# Run async unloads for model
|
||||||
asyncio.ensure_future(signal_handler_async())
|
# If an event loop doesn't exist (synchronous), exit.
|
||||||
|
try:
|
||||||
|
loop = asyncio.get_running_loop()
|
||||||
|
loop.run_until_complete(signal_handler_async())
|
||||||
|
except RuntimeError:
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
async def signal_handler_async(*_):
|
async def signal_handler_async():
|
||||||
"""Internal signal handler. Runs all async code to shut down the program."""
|
"""
|
||||||
|
Internal signal handler. Runs all async code to shut down the program.
|
||||||
|
|
||||||
|
asyncio.run will cancel all remaining tasks and close the event loop.
|
||||||
|
"""
|
||||||
|
|
||||||
if model.container:
|
if model.container:
|
||||||
await model.unload_model(skip_wait=True, shutdown=True)
|
await model.unload_model(skip_wait=True, shutdown=True)
|
||||||
@@ -34,9 +43,6 @@ async def signal_handler_async(*_):
|
|||||||
if model.embeddings_container:
|
if model.embeddings_container:
|
||||||
await model.unload_embedding_model()
|
await model.unload_embedding_model()
|
||||||
|
|
||||||
# Exit the program
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
|
|
||||||
def uvicorn_signal_handler(signal_event: signal.Signals):
|
def uvicorn_signal_handler(signal_event: signal.Signals):
|
||||||
"""Overrides uvicorn's signal handler."""
|
"""Overrides uvicorn's signal handler."""
|
||||||
|
|||||||
Reference in New Issue
Block a user