From 1735b8863e2347857e255c151ddd3cfb55bb9ea9 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 15 Nov 2022 21:04:34 -0800 Subject: [PATCH] ruff: Fix B012 return inside finally blocks. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit return inside finally blocks causes exceptions to be silenced. Although these blocks follow blanket ‘except Exception’ handlers, they do not seem to have a goal of silencing BaseException and exceptions thrown by the exception handler, so rewrite them to avoid it. Signed-off-by: Anders Kaseorg --- zerver/tornado/event_queue.py | 2 +- zerver/worker/queue_processors.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/zerver/tornado/event_queue.py b/zerver/tornado/event_queue.py index c8f3304834..fa57b08b63 100644 --- a/zerver/tornado/event_queue.py +++ b/zerver/tornado/event_queue.py @@ -208,7 +208,7 @@ class ClientDescriptor: ) finally: self.disconnect_handler() - return True + return True return False def accepts_event(self, event: Mapping[str, Any]) -> bool: diff --git a/zerver/worker/queue_processors.py b/zerver/worker/queue_processors.py index 48d278102c..b474e4f1f3 100644 --- a/zerver/worker/queue_processors.py +++ b/zerver/worker/queue_processors.py @@ -339,16 +339,16 @@ class QueueProcessingWorker(ABC): # especially since the queue might go idle until new events come in. self.update_statistics() self.idle = True - return - - self.consume_iteration_counter += 1 - if ( - self.consume_iteration_counter >= self.CONSUME_ITERATIONS_BEFORE_UPDATE_STATS_NUM - or time.time() - self.last_statistics_update_time - >= self.MAX_SECONDS_BEFORE_UPDATE_STATS - ): - self.consume_iteration_counter = 0 - self.update_statistics() + else: + self.consume_iteration_counter += 1 + if ( + self.consume_iteration_counter + >= self.CONSUME_ITERATIONS_BEFORE_UPDATE_STATS_NUM + or time.time() - self.last_statistics_update_time + >= self.MAX_SECONDS_BEFORE_UPDATE_STATS + ): + self.consume_iteration_counter = 0 + self.update_statistics() def consume_single_event(self, event: Dict[str, Any]) -> None: consume_func = lambda events: self.consume(events[0])