Example #1
0
 def __init__(self, name=None, maxsize=0, time_extension=None):
     """
     :param maxsize:
         0 by default which means store as more cache k/v as the system can
     :param time_extension:
         When a cache item has been hit, the expire_time will be refreshed
         to the greater one, either (TIME_EXTENSION + time.time() or
           (TIME_EXTENSION + expire_sec)
     """
     if name is not None:
         self._name = name
     else:
         self._name = 'cache.noname.{0}'.format(uuid.uuid4())
         log.warn(
             'You initialize the KVCache with no name. Strongly suggest'
             'you pick up a meaningful name for it in order to debug'
         )
     self._sorted_keys = queue.PriorityQueue(maxsize=maxsize)
     self._maxsize = maxsize
     self._kv_data = {}
     self._lock = thread.RWLock()
     if time_extension is None:
         self._time_extension = self.TIME_EXTENSION
     else:
         self._time_extension = time_extension
Example #2
0
 def __init__(self, maxsize=0):
     """
     :param maxsize:
         not used yet, for future use
     """
     self._maxsize = maxsize
     self._kv_data = {}
     self._lock = thread.RWLock()
Example #3
0
def test_rw_rw_lock():
    lock = thread.RWLock()
    lock.acquire_writelock(None)
    try:
        lock.acquire_writelock(1)
    except RuntimeError as error:
        pass
    try:
        lock.acquire_readlock(1)
    except RuntimeError as error:
        pass
    lock.release_writelock()
Example #4
0
 def __init__(self):
     # store kv_data
     self._kv_data = {}
     self._lock = thread.RWLock()
Example #5
0
 def __init__(self, maxsize=0):
     # store kv_data
     self._kv_data = {}
     self._orderedqueue = queue.PriorityQueue()
     self._lock = thread.RWLock()