From ddb88eb1c903f3a17ebb84011900adc45847c6cb Mon Sep 17 00:00:00 2001 From: Job Evers-Meltzer Date: Wed, 5 Oct 2016 14:16:54 -0500 Subject: [PATCH] move LoopingCallManager to own module --- lbrynet/core/looping_call_manager.py | 22 ++++++++++++++++++++++ lbrynet/lbrynet_daemon/Daemon.py | 26 ++++---------------------- 2 files changed, 26 insertions(+), 22 deletions(-) create mode 100644 lbrynet/core/looping_call_manager.py diff --git a/lbrynet/core/looping_call_manager.py b/lbrynet/core/looping_call_manager.py new file mode 100644 index 000000000..ac8986d07 --- /dev/null +++ b/lbrynet/core/looping_call_manager.py @@ -0,0 +1,22 @@ + + +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() diff --git a/lbrynet/lbrynet_daemon/Daemon.py b/lbrynet/lbrynet_daemon/Daemon.py index abcae16af..8fc1c1653 100644 --- a/lbrynet/lbrynet_daemon/Daemon.py +++ b/lbrynet/lbrynet_daemon/Daemon.py @@ -28,6 +28,9 @@ from lbrynet import __version__ as lbrynet_version # TODO: importing this when internet is disabled raises a socket.gaierror from lbryum.version import LBRYUM_VERSION as lbryum_version from lbrynet import analytics +from lbrynet.core.looping_call_manager import LoopingCallManager +from lbrynet.core.PaymentRateManager import PaymentRateManager +from lbrynet.core.server.BlobAvailabilityHandler import BlobAvailabilityHandlerFactory from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory from lbrynet.core.server.ServerProtocol import ServerProtocolFactory from lbrynet.core.Error import UnknownNameError, InsufficientFundsError, InvalidNameError @@ -135,27 +138,6 @@ class Parameters(object): self.__dict__.update(kwargs) -class LoopingCallManager(object): - def __init__(self): - self.calls = {} - - def register_looping_call(self, name, *args): - self.calls[name] = LoopingCall(*args) - - 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() - - class CheckInternetConnection(object): def __init__(self, daemon): self.daemon = daemon @@ -422,7 +404,7 @@ class Daemon(jsonrpc.JSONRPC): ('pending_claim_checker', self._check_pending_claims), ] for name, fn in looping_calls: - self.looping_call_manager.register_looping_call(name, fn) + self.looping_call_manager.register_looping_call(name, LoopingCall(fn)) self.sd_identifier = StreamDescriptorIdentifier() self.stream_info_manager = TempEncryptedFileMetadataManager()