Пример #1
0
 def _load(self, json_dict):
     ### nice to have also load the cache config ..... 
     for channel in self.db():
         self.drop(channel)
     Backend._ref_counter = sdict({ ch : sdict({ cons : ToxicSet(task_s) 
             for cons, task_s in chan_ref.items() 
             })
             for ch, chan_ref in json_dict.items()
     })
     for channel in Backend._ref_counter:
         self.db(channel)
Пример #2
0
 def sync(self):
     task_per_chan = sdict()
     for chan, gc in Backend._ref_counter.items():
         task_per_chan += sdict({ chan :ToxicSet( [ l for x in  gc.values() for l in x]) })
     new_ref_counter = Backend._ref_counter.copy()
     for chan, tasks in task_per_chan.items():
         for task_id in tasks:
             # dont test for False but for Non existent values
             # still payload that are {} are as interesting as nothing
             if not self.get(chan, task_id):
                 for cons in Backend._ref_counter[chan]:
                     new_ref_counter[chan][cons] -= ToxicSet({ task_id })
     del(Backend._ref_counter)
     Backend._ref_counter = new_ref_counter
Пример #3
0
 def setUp(self):
     self.easy = vdict( x=1, y=1, z=0)
     
     self.tree = sdict(
         a = 1,
         b = dict(
             c = 3.0,
             d = dict(e=True)
         ),
         point = self.easy
     )
Пример #4
0
 def dec_ref(self, channel_name, consumer, event_id):
     seen=False
     Backend._ref_counter[channel_name] -= sdict({ 
             consumer :ToxicSet([event_id])
     })
     for all_gc in Backend._ref_counter[channel_name].values():
         if {event_id} & all_gc:
             seen = True
             continue
     if not seen:
         self.free(channel_name, event_id)
Пример #5
0
 def __init__(self, **option):
     self.backup_name = option.get("name", 'garbage_collector')
     if Backend._db is None:
         Backend._db = sdict()
     if "cache_maker" not in option:
         from repoze.lru import LRUCache
     self.cache_maker = option.get("cache_maker",
         lambda name: LRUCache(1000000)
     )
     self.option = option
     self.backend_has_expiry_time = option.get("backend_has_expiry_time", True)
Пример #6
0
 def register(self, channel_name, lurker):
     """register a lurker for channel"""
     if channel_name not in Backend._db:
         self.db(channel_name)
         Backend._ref_counter[channel_name] = sdict()
     Backend._ref_counter[channel_name] += sdict( {lurker : ToxicSet([]) })