mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-27 17:35:07 +01:00
Allow user to quit application from the terminal via SIGINT
Call python interpreter at regular interval to handle any interrupt signals. create custom handler to terminate server and application
This commit is contained in:
parent
43301d488a
commit
32ac1ea1b6
1 changed files with 14 additions and 1 deletions
15
src/main.py
15
src/main.py
|
@ -1,4 +1,5 @@
|
|||
# Standard Packages
|
||||
import signal
|
||||
import sys
|
||||
|
||||
# External Packages
|
||||
|
@ -6,7 +7,7 @@ import uvicorn
|
|||
from fastapi import FastAPI
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from PyQt6 import QtWidgets
|
||||
from PyQt6.QtCore import QThread
|
||||
from PyQt6.QtCore import QThread, QTimer
|
||||
|
||||
# Internal Packages
|
||||
from src.configure import configure_server
|
||||
|
@ -49,12 +50,24 @@ def run():
|
|||
if args.config is None:
|
||||
configure_screen.show()
|
||||
|
||||
# Setup Signal Handlers
|
||||
signal.signal(signal.SIGINT, sigint_handler)
|
||||
# Invoke python Interpreter every 500ms to handle signals
|
||||
timer = QTimer()
|
||||
timer.start(500)
|
||||
timer.timeout.connect(lambda: None)
|
||||
|
||||
# Start Application
|
||||
server.start()
|
||||
gui.aboutToQuit.connect(server.terminate)
|
||||
gui.exec()
|
||||
|
||||
|
||||
def sigint_handler(*args):
|
||||
print("\nShutting down Khoj...")
|
||||
QtWidgets.QApplication.quit()
|
||||
|
||||
|
||||
def set_state(args):
|
||||
state.config_file = args.config_file
|
||||
state.config = args.config
|
||||
|
|
Loading…
Reference in a new issue