Handle SIGINT, SIGTERM, SIGUP and SIGQUIT

This commit is contained in:
miruka 2020-07-16 23:16:21 -04:00
parent aff5f45ca0
commit f316a24550
2 changed files with 18 additions and 2 deletions

View File

@ -14,9 +14,9 @@ class.
"""
import asyncio
import atexit
import logging as log
import os
import pyotherside
import signal
import traceback
from concurrent.futures import Future
@ -24,6 +24,8 @@ from operator import attrgetter
from threading import Thread
from typing import Coroutine, Sequence
import pyotherside
from .pyotherside_events import CoroutineDone, LoopException

View File

@ -12,7 +12,7 @@
#include <QQuickStyle>
#include <QFontDatabase>
#include <QDateTime>
#include <QDebug>
#include <signal.h>
#ifdef Q_OS_UNIX
#include <unistd.h>
@ -77,6 +77,11 @@ void loggingHandler(
}
void onExitSignal(int signum) {
QApplication::exit(128 + signum);
}
int main(int argc, char *argv[]) {
qInstallMessageHandler(loggingHandler);
@ -88,6 +93,15 @@ int main(int argc, char *argv[]) {
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
// Register handlers for quit signals, e.g. SIGINT/Ctrl-C in unix terminals
signal(SIGINT, onExitSignal);
signal(SIGTERM, onExitSignal);
#ifdef Q_OS_UNIX
signal(SIGQUIT, onExitSignal);
signal(SIGHUP, onExitSignal);
#endif
// Force the default universal QML style, notably prevents
// KDE from hijacking base controls and messing up everything
QQuickStyle::setStyle("Fusion");