diff options
-rw-r--r-- | alot/db/manager.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/alot/db/manager.py b/alot/db/manager.py index aa67ed40..56f71bd1 100644 --- a/alot/db/manager.py +++ b/alot/db/manager.py @@ -4,6 +4,7 @@ import abc import asyncio +from concurrent.futures import ThreadPoolExecutor from contextlib import closing from functools import partialmethod import logging @@ -232,16 +233,18 @@ class DBManager: async def _db_write_task(self): # this task serialises write operations on the database and # sends them off to a thread so they do not block the event loop - while True: - cur_item = await self._write_queue.get() - if cur_item is None: - self._write_queue.task_done() - break + # one workers, as there can be only one DB writer at any moment + with ThreadPoolExecutor(max_workers = 1) as executor: + while True: + cur_item = await self._write_queue.get() + if cur_item is None: + self._write_queue.task_done() + break - logging.debug('submitting write task: %s', cur_item) + logging.debug('submitting write task: %s', cur_item) - await self._loop.run_in_executor(None, cur_item.apply) - self._write_queue.task_done() + await self._loop.run_in_executor(executor, cur_item.apply) + self._write_queue.task_done() def tags_add(self, query, tags): """ |