Skip to content

Commit

Permalink
Merge pull request #271 from michaelfeil/fix-preload-only-exit-code
Browse files Browse the repository at this point in the history
add option to kill later
  • Loading branch information
michaelfeil authored Jun 19, 2024
2 parents 190fbc7 + bdd335c commit 6e0077a
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions libs/infinity_emb/infinity_emb/infinity_server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import asyncio
import os
import signal
import sys
import time
from contextlib import asynccontextmanager
Expand Down Expand Up @@ -66,14 +69,17 @@ async def lifespan(app: FastAPI):
)

if preload_only:
# this is a hack to exit the process after 3 seconds
async def kill_later(seconds: int):
await asyncio.sleep(seconds)
os.kill(os.getpid(), signal.SIGINT)

logger.info(
f"Preloaded configuration successfully. {engine_args_list} "
" -> Non-graceful exit ."
" -> exit ."
)
# skip the blocking part
else:
# application is blocking here!
yield
asyncio.create_task(kill_later(3))
yield
await app.engine_array.astop() # type: ignore
# shutdown!

Expand Down

0 comments on commit 6e0077a

Please sign in to comment.