Skip to content

Commit eeff99f

Browse files
Copilotlstein
andauthored
Fix: Kill the server with one keyboard interrupt (#94)
* Initial plan * Handle KeyboardInterrupt in run_app to allow single Ctrl+C shutdown Co-authored-by: lstein <111189+lstein@users.noreply.github.com> * Force os._exit(0) on KeyboardInterrupt to avoid hanging on background threads Co-authored-by: lstein <111189+lstein@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: lstein <111189+lstein@users.noreply.github.com>
1 parent e098123 commit eeff99f

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

invokeai/app/run_app.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ def get_app():
99

1010
def run_app() -> None:
1111
"""The main entrypoint for the app."""
12+
import os
13+
1214
from invokeai.frontend.cli.arg_parser import InvokeAIArgs
1315

1416
# Parse the CLI arguments before doing anything else, which ensures CLI args correctly override settings from other
@@ -100,4 +102,9 @@ def run_app() -> None:
100102
for hdlr in logger.handlers:
101103
uvicorn_logger.addHandler(hdlr)
102104

103-
loop.run_until_complete(server.serve())
105+
try:
106+
loop.run_until_complete(server.serve())
107+
except KeyboardInterrupt:
108+
logger.info("InvokeAI shutting down...")
109+
# Force exit to avoid hanging on non-daemon background threads (e.g. model install service).
110+
os._exit(0)

0 commit comments

Comments
 (0)