From c6c8171a681cb2d7a4abad8d1346e200b73d8800 Mon Sep 17 00:00:00 2001 From: Jotham Apaloo Date: Tue, 20 Feb 2018 16:31:27 -0800 Subject: [PATCH] Revert "Leave initialization in c'tor, just call start() where needed" This reverts commit d41ceabe82c2c459232b68438564817e7d2ef768. Which I suspect does not work because the thread is stateful, i.e. after os.fork the thread in copy of the process thinks it has already been started, even though it is not alive. Probably safest to just get a new thread instance if a thread is not alive. --- logzio/sender.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/logzio/sender.py b/logzio/sender.py index 8ed7c0d..eb88a5a 100644 --- a/logzio/sender.py +++ b/logzio/sender.py @@ -34,15 +34,19 @@ class LogzioSender: # Create a queue to hold logs self.queue = queue.Queue() + self._initialize_sending_thread() + + def _initialize_sending_thread(self): self.sending_thread = Thread(target=self._drain_queue) self.sending_thread.daemon = False self.sending_thread.name = "logzio-sending-thread" self.sending_thread.start() def append(self, logs_message): - # Queue lib is thread safe, no issue here if not self.sending_thread.is_alive(): - self.sending_thread.start() + self._initialize_sending_thread() + + # Queue lib is thread safe, no issue here self.queue.put(json.dumps(logs_message)) def flush(self):