remove tmp file when closing app with signal sigterm or sigint
This commit is contained in:
@@ -42,6 +42,7 @@ class LogFileModel:
|
|||||||
|
|
||||||
with self._lock:
|
with self._lock:
|
||||||
# TODO handle lines longer than 4096 bytes
|
# TODO handle lines longer than 4096 bytes
|
||||||
|
# TODO abort file open after a few secons: https://docs.python.org/3/library/signal.html#example
|
||||||
with open(self._file, 'rb') as f:
|
with open(self._file, 'rb') as f:
|
||||||
offset = min(byte_offset, self.byte_count())
|
offset = min(byte_offset, self.byte_count())
|
||||||
offset = max(0, offset - self.settings.max_line_length())
|
offset = max(0, offset - self.settings.max_line_length())
|
||||||
|
|||||||
28
main.py
28
main.py
@@ -1,5 +1,7 @@
|
|||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import signal
|
||||||
|
|
||||||
from PyQt6 import QtCore
|
from PyQt6 import QtCore
|
||||||
from PyQt6.lupdate import lupdate
|
from PyQt6.lupdate import lupdate
|
||||||
@@ -15,10 +17,13 @@ from tabs import Tabs
|
|||||||
|
|
||||||
MAX_LINE_LENGTH = 4096
|
MAX_LINE_LENGTH = 4096
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
log = logging.getLogger("main")
|
||||||
|
|
||||||
class MainWindow(QMainWindow):
|
class MainWindow(QMainWindow):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(MainWindow, self).__init__(*args, **kwargs)
|
super(MainWindow, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
self.settings = Settings()
|
self.settings = Settings()
|
||||||
self.setWindowTitle(self.tr("RavenLog"))
|
self.setWindowTitle(self.tr("RavenLog"))
|
||||||
self.setGeometry(0, 0, 640, 480)
|
self.setGeometry(0, 0, 640, 480)
|
||||||
@@ -84,6 +89,17 @@ class MainWindow(QMainWindow):
|
|||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
|
|
||||||
|
def stop_signal(signum, _stackframe):
|
||||||
|
""" Handle terminate signal """
|
||||||
|
try:
|
||||||
|
log.info("Terminate signal received. %s", signum)
|
||||||
|
QtCore.QCoreApplication.quit()
|
||||||
|
except Exception:
|
||||||
|
log.exception("Exception occured while terminating")
|
||||||
|
sys.exit(1)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
|
||||||
@@ -91,7 +107,19 @@ if __name__ == "__main__":
|
|||||||
#if translator.load(QLocale("de"), "messages_de.ts"):
|
#if translator.load(QLocale("de"), "messages_de.ts"):
|
||||||
# app.installTranslator(translator)
|
# app.installTranslator(translator)
|
||||||
|
|
||||||
|
# workaround to make signals work in QT apps.
|
||||||
|
# They do not work out of the box, because the main thread
|
||||||
|
# is running in C++ code once app.exec() is executed
|
||||||
|
# Forcing an empty lambda to be executed periodically gives
|
||||||
|
# control back to python and allows python to react to signals
|
||||||
|
timer = QTimer()
|
||||||
|
timer.timeout.connect(lambda: None)
|
||||||
|
timer.start(500)
|
||||||
|
|
||||||
window = MainWindow()
|
window = MainWindow()
|
||||||
window.show()
|
window.show()
|
||||||
|
|
||||||
|
signal.signal(signal.SIGINT, stop_signal)
|
||||||
|
signal.signal(signal.SIGTERM, stop_signal)
|
||||||
|
|
||||||
app.exec()
|
app.exec()
|
||||||
|
|||||||
Reference in New Issue
Block a user