From 4fb8c2c5e17d90d27aeca5e4bd0e9c5762d33535 Mon Sep 17 00:00:00 2001 From: sabaimran Date: Wed, 16 Aug 2023 21:23:59 -0700 Subject: [PATCH] Pass a SIGTERM to tell the uvicorn server to exit and gracefully kill the thread --- src/khoj/interface/desktop/main_window.py | 6 ++++++ src/khoj/main.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/khoj/interface/desktop/main_window.py b/src/khoj/interface/desktop/main_window.py index 3f827a0f..45f82701 100644 --- a/src/khoj/interface/desktop/main_window.py +++ b/src/khoj/interface/desktop/main_window.py @@ -1,5 +1,7 @@ # Standard Packages import webbrowser +import os +import signal # External Packages from PySide6 import QtGui, QtWidgets @@ -21,6 +23,10 @@ class ServerThread(QThread): def run(self): self.start_server_func() + def exit(self): + os.kill(os.getpid(), signal.SIGTERM) + super(ServerThread, self).exit() + class MainWindow(QtWidgets.QMainWindow): """Create Window to Navigate users to the web UI""" diff --git a/src/khoj/main.py b/src/khoj/main.py index cb633bba..70976454 100644 --- a/src/khoj/main.py +++ b/src/khoj/main.py @@ -123,7 +123,7 @@ def run(): # Start Application server.start() - gui.aboutToQuit.connect(server.terminate) + gui.aboutToQuit.connect(server.exit) # Close Splash Screen if still open if system() != "Darwin":