Skip to content
Snippets Groups Projects
Commit c15ef584 authored by Sybren A. Stüvel's avatar Sybren A. Stüvel
Browse files

Lock TaskUpdateQueue.flush()

This way it can be called from multiple coroutines without getting race
conditions.
parent c07105e0
No related branches found
No related tags found
No related merge requests found
......@@ -29,6 +29,7 @@ class TaskUpdateQueue:
_stuff_queued = attr.ib(default=attr.Factory(asyncio.Event), init=False)
_db = attr.ib(default=None, init=False)
_queue_lock = attr.ib(default=attr.Factory(asyncio.Lock), init=False)
_log = attrs_extra.log('%s.TaskUpdateQueue' % __name__)
def _connect_db(self):
......@@ -127,6 +128,7 @@ class TaskUpdateQueue:
Returns True iff the queue was empty, even before flushing.
"""
with (await self._queue_lock):
queue_is_empty = True
for rowid, url, payload in self._queue():
queue_is_empty = False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment