backport some localnode improvements from peerlink

This commit is contained in:
j 2014-09-01 12:30:09 +02:00
commit e4cf322570
2 changed files with 62 additions and 33 deletions

View file

@ -358,10 +358,16 @@ class Nodes(Thread):
self._q = Queue()
self._running = True
self._local = LocalNodes()
self._cleanup = PeriodicCallback(lambda: self.queue('cleanup'), 120000)
self._cleanup.start()
Thread.__init__(self)
self.daemon = True
self.start()
def cleanup(self):
if self._running:
self._local.cleanup()
def queue(self, *args):
self._q.put(list(args))
@ -396,7 +402,9 @@ class Nodes(Thread):
while self._running:
args = self._q.get()
if args:
if args[0] == 'add':
if args[0] == 'cleanup':
self.cleanup()
elif args[0] == 'add':
self._add(args[1])
else:
self._call(*args)