summaryrefslogtreecommitdiffstats
path: root/pyfirstaidkit
diff options
context:
space:
mode:
authorMartin Sivak <msivak@redhat.com>2008-04-22 19:00:12 +0200
committerMartin Sivak <msivak@redhat.com>2008-04-22 19:00:12 +0200
commit43cb2727dcc19f102d54418cbba1887cb916b5e4 (patch)
treeff265865fd7386533b5b4279a4425d2c4a6f033f /pyfirstaidkit
parent055575bcc6bc33c29456f663dd8d75993d30427c (diff)
downloadfirstaidkit-43cb2727dcc19f102d54418cbba1887cb916b5e4.tar.gz
firstaidkit-43cb2727dcc19f102d54418cbba1887cb916b5e4.tar.xz
firstaidkit-43cb2727dcc19f102d54418cbba1887cb916b5e4.zip
Circular buffer works correctly and the baskup system doesn't stay initialized because of reporting queue anymore
Diffstat (limited to 'pyfirstaidkit')
-rw-r--r--pyfirstaidkit/reporting.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/pyfirstaidkit/reporting.py b/pyfirstaidkit/reporting.py
index 203bb1f..934a6ef 100644
--- a/pyfirstaidkit/reporting.py
+++ b/pyfirstaidkit/reporting.py
@@ -17,6 +17,8 @@
import Queue
import logging
+import thread
+import weakref
Logger = logging.getLogger("firstaidkit")
@@ -74,6 +76,7 @@ class Reports(object):
"""round - is this a round buffer?
maxsize - size of the buffer"""
self._queue = Queue.Queue(maxsize = maxsize)
+ self._queue_lock = thread.allocate_lock()
self._round = round
self._mailboxes = []
self._notify = []
@@ -91,12 +94,15 @@ class Reports(object):
destination = self._queue
try:
- ret=destination.put(data)
+ self._queue_lock.acquire()
+ ret=destination.put(data, block = False)
except Queue.Full, e:
if not self._round:
raise
destination.get() #Queue is full and it is a round buffer.. remove the oldest item and use the free space to put the new item
ret=destination.put(data)
+ finally:
+ self._queue_lock.release()
#call all the notify callbacks
for func, args, kwargs in self._notify:
@@ -107,7 +113,13 @@ class Reports(object):
def get(self, mailbox = None, *args, **kwargs):
if mailbox is None:
mailbox = self._queue
- return mailbox.get(*args, **kwargs)
+ try:
+ self._queue_lock.acquire()
+ ret = mailbox.get(*args, **kwargs)
+ finally:
+ self._queue_lock.release()
+
+ return ret
def openMailbox(self, maxsize=-1):
"""Allocate new mailbox for replies"""