Use DeferredLock instead of threading.Lock

Signed-off-by: Olivier Wilkinson (reivilibre) <olivier@librepush.net>
This commit is contained in:
Olivier Wilkinson (reivilibre) 2019-08-27 14:59:39 +01:00
parent 10c1a233f9
commit 064143c130
2 changed files with 6 additions and 4 deletions

View file

@ -66,12 +66,13 @@ class StatsHandler(StateDeltasHandler):
@defer.inlineCallbacks
def process():
yield lock.acquire()
try:
yield self._unsafe_process()
finally:
lock.release()
yield lock.release()
if lock.acquire(blocking=False):
if not lock.locked:
# we only want to run this process one-at-a-time,
# and also, if the initial background updater wants us to keep out,
# we should respect that.

View file

@ -16,7 +16,8 @@
import logging
from itertools import chain
from threading import Lock
from twisted.internet.defer import DeferredLock
from synapse.storage.state_deltas import StateDeltasStore
from synapse.util.caches.descriptors import cached
@ -57,7 +58,7 @@ class StatsStore(StateDeltasStore):
self.stats_enabled = hs.config.stats_enabled
self.stats_bucket_size = hs.config.stats_bucket_size
self.stats_delta_processing_lock = Lock()
self.stats_delta_processing_lock = DeferredLock()
self.register_noop_background_update("populate_stats_createtables")
self.register_noop_background_update("populate_stats_process_rooms")