diff options
author | Anton Khirnov <anton@khirnov.net> | 2021-01-20 11:38:34 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2021-01-20 11:39:27 +0100 |
commit | d47a85bca83352300399f04e76abecea4d53a934 (patch) | |
tree | 741f5ce3857102f19e4d44c33dc93981b906268d /alot/ui.py | |
parent | 3b78137e97565f90a48aad92dc471c47e63747eb (diff) |
db: make write operations async
Diffstat (limited to 'alot/ui.py')
-rw-r--r-- | alot/ui.py | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -104,7 +104,7 @@ class UI: # running asyncio event loop _loop = None - def __init__(self, dbman, initialcmdline): + def __init__(self, loop, dbman, initialcmdline): """ :param dbman: :class:`~alot.db.DBManager` :param initialcmdline: commandline applied after setting up interface @@ -118,8 +118,6 @@ class UI: """list of active buffers""" self.current_buffer = None """points to currently active :class:`~alot.buffers.Buffer`""" - self.db_was_locked = False - """flag used to prevent multiple 'index locked' notifications""" self.mode = 'global' """interface mode identifier - type of current buffer""" self.commandprompthistory = [] @@ -133,7 +131,7 @@ class UI: self.last_commandline = None """saves the last executed commandline""" - self._loop = asyncio.get_event_loop() + self._loop = loop # define empty notification pile self._notification_bar = urwid.Pile([]) @@ -202,6 +200,8 @@ class UI: logging.info('setup gui in %d colours', colourmode) self.mainloop.screen.set_terminal_properties(colors=colourmode) + self._loop.create_task(self.dbman.startup()) + logging.debug('fire first command') self._loop.create_task(self.apply_commandline(initialcmdline)) @@ -698,7 +698,6 @@ class UI: cb = self.current_buffer info = {} - info['pending_writes'] = len(self.dbman.writequeue) info['input_queue'] = ' '.join(self.input_queue) info['buffer_no'] = self.buffers.index(cb) info['buffer_type'] = cb.modename @@ -752,7 +751,7 @@ class UI: self.current_buffer.rebuild() self.update() - def cleanup(self): + async def cleanup(self): """Do the final clean up before shutting down.""" size = settings.get('history_size') self._save_history_to_file(self.commandprompthistory, @@ -762,6 +761,8 @@ class UI: self._save_history_to_file(self.recipienthistory, self._recipients_hist_file, size=size) + await self.dbman.shutdown() + @staticmethod def _load_history_from_file(path, size=-1): """Load a history list from a file and split it into lines. |