diff options
author | Anton Khirnov <anton@khirnov.net> | 2021-01-26 10:26:27 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2021-01-26 10:29:24 +0100 |
commit | 5cb88d559ae462dad80d346d44f12dcc9eb3ec10 (patch) | |
tree | d6971568c4f026be6ccdf6d93042c5d0c2770acc /alot/ui.py | |
parent | 6a22c9f8026f255c5e6eed5916168552138581e2 (diff) |
Rewrite mailcap handling.
Add a class that encapsulates the handler and is responsible for
managing the temporary file, if one is needed.
Use this class for both rendering inline content and displaying
attachments externally.
External attachments are now wrapped in an asyncio task that is added to
a pool of tasks managed by ui.
Diffstat (limited to 'alot/ui.py')
-rw-r--r-- | alot/ui.py | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -104,6 +104,8 @@ class UI: # running asyncio event loop _loop = None + _pending_tasks = None + def __init__(self, loop, dbman, initialcmdline): """ :param dbman: :class:`~alot.db.DBManager` @@ -133,6 +135,8 @@ class UI: self._loop = loop + self._pending_tasks = set() + # define empty notification pile self._notification_bar = urwid.Pile([]) self._footer_wgt = urwid.Pile([self._notification_bar]) @@ -758,8 +762,18 @@ class UI: self._save_history_to_file(self.recipienthistory, self._recipients_hist_file, size=size) + logging.info('cancelling pending tasks: %s', self._pending_tasks) + for t in self._pending_tasks: + t.cancel() + await asyncio.gather(*self._pending_tasks) + await self.dbman.shutdown() + def run_task(self, coro): + task = self._loop.create_task(coro) + self._pending_tasks.add(task) + task.add_done_callback(self._pending_tasks.discard) + @staticmethod def _load_history_from_file(path, size=-1): """Load a history list from a file and split it into lines. |