Force save on exit
This commit is contained in:
parent
33f357587e
commit
746ff52c8a
@ -61,16 +61,15 @@ class Data(MutableMapping):
|
|||||||
def _executor(self):
|
def _executor(self):
|
||||||
while self._trunning:
|
while self._trunning:
|
||||||
self._tevent.wait(save_delay)
|
self._tevent.wait(save_delay)
|
||||||
self._save()
|
self.save()
|
||||||
|
|
||||||
def _save(self):
|
def save(self):
|
||||||
for key in self._hot_keys:
|
for key in self._hot_keys:
|
||||||
logger.info(f"saving dict {key}")
|
logger.info(f"saving dict {key}")
|
||||||
to_write = self._cache[key] # apparently thread-safe
|
to_write = self._cache[key] # apparently thread-safe
|
||||||
with open(self.data_path.format(key), "w+") as f:
|
with open(self.data_path.format(key), "w+") as f:
|
||||||
f.write(json.dumps(to_write))
|
f.write(json.dumps(to_write))
|
||||||
self._hot_keys = set()
|
self._hot_keys = set()
|
||||||
self._saving = False
|
|
||||||
|
|
||||||
def __delitem__(self, key):
|
def __delitem__(self, key):
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
import os
|
||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
from functools import partial
|
from functools import partial
|
||||||
@ -31,9 +32,9 @@ class App:
|
|||||||
self.app = QtWidgets.QApplication(sys.argv)
|
self.app = QtWidgets.QApplication(sys.argv)
|
||||||
self.app.setQuitOnLastWindowClosed(False)
|
self.app.setQuitOnLastWindowClosed(False)
|
||||||
|
|
||||||
data = Data()
|
self.data = Data()
|
||||||
self.tasks = Tasks(data)
|
self.tasks = Tasks(self.data)
|
||||||
lcd = LogCommentsData(data)
|
lcd = LogCommentsData(self.data)
|
||||||
self.log = Log(lcd)
|
self.log = Log(lcd)
|
||||||
self._active_task = self.log.last_log() or "Nothing"
|
self._active_task = self.log.last_log() or "Nothing"
|
||||||
|
|
||||||
@ -153,7 +154,7 @@ class App:
|
|||||||
|
|
||||||
menu_items.append(("Settings", partial(self.open_new_dialog, self.settings)))
|
menu_items.append(("Settings", partial(self.open_new_dialog, self.settings)))
|
||||||
menu_items.append(("About", partial(self.open_new_dialog, self.about)))
|
menu_items.append(("About", partial(self.open_new_dialog, self.about)))
|
||||||
menu_items.append(("Close", self.app.quit))
|
menu_items.append(("Close", self.quit_handler))
|
||||||
|
|
||||||
if self.config.flip_menu:
|
if self.config.flip_menu:
|
||||||
menu_items.reverse()
|
menu_items.reverse()
|
||||||
@ -169,8 +170,10 @@ class App:
|
|||||||
action.setIcon(get_icon("go-next"))
|
action.setIcon(get_icon("go-next"))
|
||||||
action.triggered.connect(item[1])
|
action.triggered.connect(item[1])
|
||||||
|
|
||||||
def sigterm_handler(self, signo, _frame):
|
def quit_handler(self, signo=None, _frame=None):
|
||||||
|
if signo:
|
||||||
logger.debug(f'handling signal "{signal.strsignal(signo)}"')
|
logger.debug(f'handling signal "{signal.strsignal(signo)}"')
|
||||||
|
self.data.save()
|
||||||
self.app.quit()
|
self.app.quit()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
@ -178,8 +181,8 @@ class App:
|
|||||||
# interrupt event loop regularly for signal handling
|
# interrupt event loop regularly for signal handling
|
||||||
timer.timeout.connect(lambda: None)
|
timer.timeout.connect(lambda: None)
|
||||||
timer.start(500)
|
timer.start(500)
|
||||||
signal.signal(signal.SIGTERM, self.sigterm_handler)
|
signal.signal(signal.SIGTERM, self.quit_handler)
|
||||||
signal.signal(signal.SIGINT, self.sigterm_handler)
|
signal.signal(signal.SIGINT, self.quit_handler)
|
||||||
if PYSIDE_6:
|
if PYSIDE_6:
|
||||||
self.app.exec()
|
self.app.exec()
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user