diff options
author | Olivier Wilkinson (reivilibre) <olivier@librepush.net> | 2019-08-27 14:59:39 +0100 |
---|---|---|
committer | Olivier Wilkinson (reivilibre) <olivier@librepush.net> | 2019-08-27 15:00:16 +0100 |
commit | 064143c1308cf6354554702d5041ec4bd3ac8ff8 (patch) | |
tree | 05eb5bab6ff5e389c3a11c9fe72f6fefe462447f | |
parent | Fix logic error. (diff) | |
download | synapse-064143c1308cf6354554702d5041ec4bd3ac8ff8.tar.xz |
Use `DeferredLock` instead of `threading.Lock`
Signed-off-by: Olivier Wilkinson (reivilibre) <olivier@librepush.net>
-rw-r--r-- | synapse/handlers/stats.py | 5 | ||||
-rw-r--r-- | synapse/storage/stats.py | 5 |
2 files changed, 6 insertions, 4 deletions
diff --git a/synapse/handlers/stats.py b/synapse/handlers/stats.py index 2f7c108181..8e1bf8b5d5 100644 --- a/synapse/handlers/stats.py +++ b/synapse/handlers/stats.py @@ -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. diff --git a/synapse/storage/stats.py b/synapse/storage/stats.py index ede5002fca..c9687c29d2 100644 --- a/synapse/storage/stats.py +++ b/synapse/storage/stats.py @@ -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") |