lbry-sdk/lbrynet/core/looping_call_manager.py

23 lines
563 B
Python
Raw Normal View History

2016-10-05 21:16:54 +02:00
class LoopingCallManager(object):
def __init__(self):
self.calls = {}
def register_looping_call(self, name, call):
assert name not in self.calls, '{} is already registered'.format(name)
self.calls[name] = call
def start(self, name, *args):
lcall = self.calls[name]
if not lcall.running:
lcall.start(*args)
def stop(self, name):
self.calls[name].stop()
def shutdown(self):
for lcall in self.calls.itervalues():
if lcall.running:
lcall.stop()