From 8847dbbb0d5fcb504d8c4d738246daf9004e2b19 Mon Sep 17 00:00:00 2001 From: Zack Dever Date: Mon, 14 Mar 2016 16:14:48 -0700 Subject: make Sender._topics_to_add a set instead of a list --- kafka/producer/sender.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kafka/producer/sender.py b/kafka/producer/sender.py index 0e6d6cd..bba135b 100644 --- a/kafka/producer/sender.py +++ b/kafka/producer/sender.py @@ -45,7 +45,7 @@ class Sender(threading.Thread): self._metadata = client.cluster self._running = True self._force_close = False - self._topics_to_add = [] + self._topics_to_add = set() def run(self): """The main run loop for the sender thread.""" @@ -158,8 +158,9 @@ class Sender(threading.Thread): self.initiate_close() def add_topic(self, topic): - self._topics_to_add.append(topic) - self.wakeup() + if topic not in self._topics_to_add: + self._topics_to_add.add(topic) + self.wakeup() def _failed_produce(self, batches, node_id, error): log.debug("Error sending produce request to node %d: %s", node_id, error) # trace -- cgit v1.2.1