From 42c26102d82a5615e371aec4243c67706dc99a7d Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 11 Jan 2016 15:52:38 -0500 Subject: [PATCH] Make daemon shut down properly Makes the daemon shutdown properly and adds better start/stop messages. --- lbrynet/lbrynet_daemon/LBRYDaemon.py | 23 +++++++++++++++++++++-- lbrynet/lbrynet_daemon/LBRYDownloader.py | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lbrynet/lbrynet_daemon/LBRYDaemon.py b/lbrynet/lbrynet_daemon/LBRYDaemon.py index e827059bf..a503668c3 100644 --- a/lbrynet/lbrynet_daemon/LBRYDaemon.py +++ b/lbrynet/lbrynet_daemon/LBRYDaemon.py @@ -84,6 +84,10 @@ class LBRYDaemon(xmlrpc.XMLRPC): self.max_key_fee = 100.0 return defer.succeed(None) + def _disp_startup(): + print "Started LBRYnet daemon" + return defer.succeed(None) + d = defer.Deferred() d.addCallback(lambda _: _set_vars()) d.addCallback(lambda _: threads.deferToThread(self._setup_data_directory)) @@ -96,10 +100,19 @@ class LBRYDaemon(xmlrpc.XMLRPC): d.addCallback(lambda _: self._setup_lbry_file_manager()) d.addCallback(lambda _: self._setup_lbry_file_opener()) d.addCallback(lambda _: self._setup_fetcher()) + d.addCallback(lambda _: _disp_startup()) d.callback(None) return defer.succeed(None) + def _shutdown(self): + print 'Closing lbrynet session' + if self.session is not None: + d = self.session.shut_down() + else: + d = defer.Deferred() + return d + def _update_settings(self): self.data_rate = self.session_settings['data_rate'] self.max_key_fee = self.session_settings['max_key_fee'] @@ -366,8 +379,14 @@ class LBRYDaemon(xmlrpc.XMLRPC): Stop the reactor """ - reactor.stop() - return defer.succeed('Stopping') + def _disp_shutdown(): + print 'Shutting down lbrynet daemon' + + d = self._shutdown() + d.addCallback(lambda _: _disp_shutdown()) + d.addCallback(lambda _: reactor.stop()) + + return d def xmlrpc_get_lbry_files(self): """ diff --git a/lbrynet/lbrynet_daemon/LBRYDownloader.py b/lbrynet/lbrynet_daemon/LBRYDownloader.py index 42559dadd..2ca70506c 100644 --- a/lbrynet/lbrynet_daemon/LBRYDownloader.py +++ b/lbrynet/lbrynet_daemon/LBRYDownloader.py @@ -231,6 +231,7 @@ class FetcherDaemon(object): for l in conf: if l.startswith("maxkey="): settings["maxkey"] = float(l[7:].rstrip('\n')) + print "Autofetcher using max key price of", settings["maxkey"], ", to start call start_fetcher()" else: print "Autofetcher using default max key price of 0.0" print "To change this create the file:"