lbry-sdk/lbrynet/core/looping_call_manager.py

21 lines
562 B
Python
Raw Normal View History

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):
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()