Skip to content

Commit 7b51ead

Browse files
authored
Merge pull request #2 from njhale/fix/handle-interrupt
fix: gracefully exit on interrupt
2 parents f416394 + 93f4209 commit 7b51ead

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ def map_finish_reason(finish_reason: str) -> str:
357357

358358
if __name__ == "__main__":
359359
import uvicorn
360+
import asyncio
360361

361-
uvicorn.run("main:app", host="127.0.0.1", port=int(os.environ.get("PORT", "8000")),
362+
try:
363+
uvicorn.run("main:app", host="127.0.0.1", port=int(os.environ.get("PORT", "8000")),
362364
log_level="debug" if debug else "critical", reload=debug, access_log=debug)
365+
except (KeyboardInterrupt, asyncio.CancelledError):
366+
pass

0 commit comments

Comments
 (0)