Skip to content

Commit 93f4209

Browse files
committed
fix: gracefully exit on interrupt
Catch KeyboardInterrupt and asyncio.CancelledError exceptions to ensure the application exits without printing traceback on interrupt. This allows gptscript to kill the provider silently. Signed-off-by: Nick Hale <[email protected]>
1 parent f416394 commit 93f4209

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)