From 1bdbb9e2de242e80edc62d3a64afe50cbcd435f9 Mon Sep 17 00:00:00 2001 From: oliverdrake Date: Tue, 15 Jan 2013 15:06:02 +1300 Subject: [PATCH] removing threading.local code - pretty sure we don't need this as threading.Handler.handle already has a thread lock that is used to wrap every call to emit --- pylogstash/handler.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/pylogstash/handler.py b/pylogstash/handler.py index dd921aa..1263b54 100644 --- a/pylogstash/handler.py +++ b/pylogstash/handler.py @@ -2,7 +2,6 @@ import zmq import socket import datetime -import threading MAX_MESSAGES = 1000 @@ -20,19 +19,10 @@ def __init__(self, connect_string="tcp://127.0.0.1:2120", fields=[], self._connect_string = connect_string self._fields = fields self._input_type = input_type - self._local = threading.local() self._queue_length = queue_length - - @property - def publisher(self): - if not hasattr(self._local, 'publisher'): - print("creating publisher") - # 0mq sockets aren't threadsafe, so bind them into a - # threadlocal - self._local.publisher = self._context.socket(zmq.PUB) - self._local.publisher.setsockopt(zmq.HWM, self._queue_length) - self._local.publisher.connect(self._connect_string) - return self._local.publisher + self.publisher = self._context.socket(zmq.PUB) + self.publisher.setsockopt(zmq.HWM, self._queue_length) + self.publisher.connect(self._connect_string) def emit(self, record): field_dict = dict([(field, getattr(record, field)) for field in self._fields if hasattr(record, field)]) @@ -52,6 +42,4 @@ def emit(self, record): "@source_host": host, "@message": self.format(record) } - print("Shipping log") self.publisher.send_json(message) - print("message shipped")