summaryrefslogtreecommitdiff
path: root/alot/db
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-02-05 15:09:50 +0100
committerAnton Khirnov <anton@khirnov.net>2021-02-05 15:09:50 +0100
commit9137c13fe863840a83ed5afd8da10a6aa9582bef (patch)
treea56117201b99c478eea253364be6e16901fa3010 /alot/db
parenta64a9b3219d0fd9241c6fcb6960f013588950571 (diff)
db/manager: use only one worker thread for write operations
There is no point in having more, as the database cannot have more than one writer at any moment.
Diffstat (limited to 'alot/db')
-rw-r--r--alot/db/manager.py19
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):
"""