2018-07-22 00:34:59 +02:00
|
|
|
class LoopingCallManager:
|
2016-10-19 01:09:35 +02:00
|
|
|
def __init__(self, calls=None):
|
|
|
|
self.calls = calls or {}
|
2016-10-05 21:16:54 +02:00
|
|
|
|
|
|
|
def register_looping_call(self, name, call):
|
2018-10-18 12:42:45 +02:00
|
|
|
assert name not in self.calls, f'{name} is already registered'
|
2016-10-05 21:16:54 +02:00
|
|
|
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):
|
2018-07-12 05:18:59 +02:00
|
|
|
for lcall in self.calls.values():
|
2016-10-05 21:16:54 +02:00
|
|
|
if lcall.running:
|
|
|
|
lcall.stop()
|