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:
Debanjum Singh Solanky 2022-08-12 21:02:18 +03:00
parent 43301d488a
commit 32ac1ea1b6

View file

@ -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