def __init__(self, data_dir, checkpoint_operations=100, checkpoint_timeout=30): """ @param data_dir: The directory where DBM files will be stored. @param data_dir: C{str} @param checkpoint_operations: Number of operations between syncs. @type checkpoint_operations: C{int} @param checkpoint_timeout: Max time (in seconds) that can elapse between sync of cache. @type checkpoint_timeout: C{float} """ QueueStore.__init__(self) self._opcount = 0 self._last_sync = datetime.now() self.data_dir = data_dir self.checkpoint_operations = checkpoint_operations self.checkpoint_timeout = timedelta(seconds=checkpoint_timeout) # Should this be in constructor? # The queue metadata stores mutable (dict) objects. For this reason we set # writeback=True and rely on the sync() method to keep the cache & disk # in-sync. self.queue_metadata = shelve.open(os.path.join( self.data_dir, 'metadata'), writeback=True) # Since we do not need mutable objects on the frame stores (we don't modify them, we just # put/get values), we do NOT use writeback=True here. This should also conserve on memory # usage, since apparently that can get hefty with the caching when # writeback=True. self.frame_store = shelve.open(os.path.join( self.data_dir, 'frames'), writeback=False)
def __init__(self, data_dir, checkpoint_operations=100, checkpoint_timeout=30): """ @param data_dir: The directory where DBM files will be stored. @param data_dir: C{str} @param checkpoint_operations: Number of operations between syncs. @type checkpoint_operations: C{int} @param checkpoint_timeout: Max time (in seconds) that can elapse between sync of cache. @type checkpoint_timeout: C{float} """ QueueStore.__init__(self) self._opcount = 0 self._last_sync = datetime.now() self.data_dir = data_dir self.checkpoint_operations = checkpoint_operations self.checkpoint_timeout = timedelta(seconds=checkpoint_timeout) # Should this be in constructor? # The queue metadata stores mutable (dict) objects. For this reason we set # writeback=True and rely on the sync() method to keep the cache & disk in-sync. self.queue_metadata = shelve.open(os.path.join(self.data_dir, 'metadata'), writeback=True) # Since we do not need mutable objects on the frame stores (we don't modify them, we just # put/get values), we do NOT use writeback=True here. This should also conserve on memory # usage, since apparently that can get hefty with the caching when writeback=True. self.frame_store = shelve.open(os.path.join(self.data_dir, 'frames'), writeback=False)
def __init__(self): QueueStore.__init__(self) self._messages = defaultdict(deque)