mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-08 05:39:13 +00: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:
15
src/main.py
15
src/main.py
@@ -1,4 +1,5 @@
|
|||||||
# Standard Packages
|
# Standard Packages
|
||||||
|
import signal
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# External Packages
|
# External Packages
|
||||||
@@ -6,7 +7,7 @@ import uvicorn
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
from PyQt6 import QtWidgets
|
from PyQt6 import QtWidgets
|
||||||
from PyQt6.QtCore import QThread
|
from PyQt6.QtCore import QThread, QTimer
|
||||||
|
|
||||||
# Internal Packages
|
# Internal Packages
|
||||||
from src.configure import configure_server
|
from src.configure import configure_server
|
||||||
@@ -49,12 +50,24 @@ def run():
|
|||||||
if args.config is None:
|
if args.config is None:
|
||||||
configure_screen.show()
|
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
|
# Start Application
|
||||||
server.start()
|
server.start()
|
||||||
gui.aboutToQuit.connect(server.terminate)
|
gui.aboutToQuit.connect(server.terminate)
|
||||||
gui.exec()
|
gui.exec()
|
||||||
|
|
||||||
|
|
||||||
|
def sigint_handler(*args):
|
||||||
|
print("\nShutting down Khoj...")
|
||||||
|
QtWidgets.QApplication.quit()
|
||||||
|
|
||||||
|
|
||||||
def set_state(args):
|
def set_state(args):
|
||||||
state.config_file = args.config_file
|
state.config_file = args.config_file
|
||||||
state.config = args.config
|
state.config = args.config
|
||||||
|
|||||||
Reference in New Issue
Block a user