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 asyncio
import atexit
import logging as log import logging as log
import os import os
import pyotherside
import signal import signal
import traceback import traceback
from concurrent.futures import Future from concurrent.futures import Future
@ -24,6 +24,8 @@ from operator import attrgetter
from threading import Thread from threading import Thread
from typing import Coroutine, Sequence from typing import Coroutine, Sequence
import pyotherside
from .pyotherside_events import CoroutineDone, LoopException from .pyotherside_events import CoroutineDone, LoopException

View File

@ -12,7 +12,7 @@
#include <QQuickStyle> #include <QQuickStyle>
#include <QFontDatabase> #include <QFontDatabase>
#include <QDateTime> #include <QDateTime>
#include <QDebug> #include <signal.h>
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
#include <unistd.h> #include <unistd.h>
@ -77,6 +77,11 @@ void loggingHandler(
} }
void onExitSignal(int signum) {
QApplication::exit(128 + signum);
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
qInstallMessageHandler(loggingHandler); qInstallMessageHandler(loggingHandler);
@ -88,6 +93,15 @@ int main(int argc, char *argv[]) {
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv); 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 // Force the default universal QML style, notably prevents
// KDE from hijacking base controls and messing up everything // KDE from hijacking base controls and messing up everything
QQuickStyle::setStyle("Fusion"); QQuickStyle::setStyle("Fusion");