From 2bc2687be3339b38513728a2a3a61b24e1660677 Mon Sep 17 00:00:00 2001 From: hoseinaghaei Date: Thu, 15 Feb 2024 04:50:11 +0330 Subject: [PATCH] use singleton on subscribers. --- kafka_server/broker/file/read.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kafka_server/broker/file/read.py b/kafka_server/broker/file/read.py index 84b663a..77d9c3c 100644 --- a/kafka_server/broker/file/read.py +++ b/kafka_server/broker/file/read.py @@ -29,12 +29,12 @@ def __new__(cls, *args, **kwargs): return cls._instance def __init__(self, partition: str, replica: str): - self.subscribers = None if not hasattr(self, 'initialized'): self.partition = partition self.message_in_fly = False self.message_in_fly_since = datetime.now() self.segment = Segment(partition, replica) + self.subscribers = self.get_subscribers() self.initialized = True self.toggle_thread = threading.Thread(target=self.toggle_message_in_fly) @@ -51,7 +51,9 @@ def toggle_message_in_fly(self): time.sleep(5) def read_data(self): - self.subscribers = self.get_subscribers() + if len(self.subscribers) == 0: + self.subscribers = self.get_subscribers() + if len(self.subscribers) == 0: print("No subscribers") return None, None