From 5bccfdb2445c7ef023e68bf2cdee85efa0e804b9 Mon Sep 17 00:00:00 2001 From: Job Evers-Meltzer Date: Thu, 3 Nov 2016 14:42:45 -0500 Subject: [PATCH] add logging to shutdown process --- lbrynet/core/BlobAvailability.py | 3 ++- lbrynet/core/RateLimiter.py | 7 +++++++ lbrynet/core/Session.py | 3 ++- lbrynet/core/Wallet.py | 3 +-- lbrynet/core/client/DHTPeerFinder.py | 6 ++++++ lbrynet/core/server/DHTHashAnnouncer.py | 8 +++++++- lbrynet/lbryfilemanager/EncryptedFileManager.py | 2 +- lbrynet/lbrynet_daemon/Daemon.py | 8 +++++--- packaging/osx/lbry-osx-app/lbrygui/LBRYApp.py | 1 + 9 files changed, 32 insertions(+), 9 deletions(-) diff --git a/lbrynet/core/BlobAvailability.py b/lbrynet/core/BlobAvailability.py index 6cfe52852..5131a7cd4 100644 --- a/lbrynet/core/BlobAvailability.py +++ b/lbrynet/core/BlobAvailability.py @@ -25,11 +25,12 @@ class BlobAvailabilityTracker(object): self._check_mine = LoopingCall(self._update_mine) def start(self): - log.info("Starting blob tracker") + log.info("Starting %s", self) self._check_popular.start(30) self._check_mine.start(120) def stop(self): + log.info("Stopping %s", self) if self._check_popular.running: self._check_popular.stop() if self._check_mine.running: diff --git a/lbrynet/core/RateLimiter.py b/lbrynet/core/RateLimiter.py index 2063dd939..04b153577 100644 --- a/lbrynet/core/RateLimiter.py +++ b/lbrynet/core/RateLimiter.py @@ -1,8 +1,13 @@ +import logging + from zope.interface import implements from lbrynet.interfaces import IRateLimiter from twisted.internet import task +log = logging.getLogger(__name__) + + class DummyRateLimiter(object): def __init__(self): self.dl_bytes_this_second = 0 @@ -64,6 +69,7 @@ class RateLimiter(object): self.protocols = [] def start(self): + log.info("Starting %s", self) self.tick_call = task.LoopingCall(self.tick) self.tick_call.start(self.tick_interval) @@ -74,6 +80,7 @@ class RateLimiter(object): self.unthrottle_ul() def stop(self): + log.info("Stopping %s", self) if self.tick_call is not None: self.tick_call.stop() self.tick_call = None diff --git a/lbrynet/core/Session.py b/lbrynet/core/Session.py index 5b33bfd6d..450e4e556 100644 --- a/lbrynet/core/Session.py +++ b/lbrynet/core/Session.py @@ -169,6 +169,7 @@ class Session(object): def shut_down(self): """Stop all services""" + log.info('Shutting down %s', self) ds = [] if self.blob_manager is not None: ds.append(defer.maybeDeferred(self.blob_tracker.stop)) @@ -323,7 +324,7 @@ class Session(object): return dl def _unset_upnp(self): - + log.info("Unsetting upnp for %s", self) def threaded_unset_upnp(): u = miniupnpc.UPnP() num_devices_found = u.discover() diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index 3bfb41287..1e3f72567 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -97,9 +97,8 @@ class Wallet(object): log.error("An error occurred stopping the wallet: %s", err.getTraceback()) def stop(self): - + log.info("Stopping %s", self) self.stopped = True - # If self.next_manage_call is None, then manage is currently running or else # start has not been called, so set stopped and do nothing else. if self.next_manage_call is not None: diff --git a/lbrynet/core/client/DHTPeerFinder.py b/lbrynet/core/client/DHTPeerFinder.py index ab5dd1b3a..46c34ee52 100644 --- a/lbrynet/core/client/DHTPeerFinder.py +++ b/lbrynet/core/client/DHTPeerFinder.py @@ -1,8 +1,13 @@ import binascii +import logging + from zope.interface import implements from lbrynet.interfaces import IPeerFinder +log = logging.getLogger(__name__) + + class DHTPeerFinder(object): """This class finds peers which have announced to the DHT that they have certain blobs""" implements(IPeerFinder) @@ -21,6 +26,7 @@ class DHTPeerFinder(object): self.next_manage_call = reactor.callLater(60, self.run_manage_loop) def stop(self): + log.info("Stopping %s", self) if self.next_manage_call is not None and self.next_manage_call.active(): self.next_manage_call.cancel() self.next_manage_call = None diff --git a/lbrynet/core/server/DHTHashAnnouncer.py b/lbrynet/core/server/DHTHashAnnouncer.py index 574f50ceb..eca877f73 100644 --- a/lbrynet/core/server/DHTHashAnnouncer.py +++ b/lbrynet/core/server/DHTHashAnnouncer.py @@ -1,6 +1,11 @@ import binascii -from twisted.internet import defer, reactor import collections +import logging + +from twisted.internet import defer, reactor + + +log = logging.getLogger(__name__) class DHTHashAnnouncer(object): @@ -22,6 +27,7 @@ class DHTHashAnnouncer(object): self.next_manage_call = reactor.callLater(60, self.run_manage_loop) def stop(self): + log.info("Stopping %s", self) if self.next_manage_call is not None: self.next_manage_call.cancel() self.next_manage_call = None diff --git a/lbrynet/lbryfilemanager/EncryptedFileManager.py b/lbrynet/lbryfilemanager/EncryptedFileManager.py index 9c774d3d9..996c9bd28 100644 --- a/lbrynet/lbryfilemanager/EncryptedFileManager.py +++ b/lbrynet/lbryfilemanager/EncryptedFileManager.py @@ -160,7 +160,7 @@ class EncryptedFileManager(object): return defer.fail(Failure(ValueError("Could not find that LBRY file"))) def stop(self): - + log.info('Stopping %s', self) ds = [] def wait_for_finished(lbry_file, count=2): diff --git a/lbrynet/lbrynet_daemon/Daemon.py b/lbrynet/lbrynet_daemon/Daemon.py index 6e9692ece..48e758df4 100644 --- a/lbrynet/lbrynet_daemon/Daemon.py +++ b/lbrynet/lbrynet_daemon/Daemon.py @@ -560,6 +560,7 @@ class Daemon(AuthJSONRPCServer): try: if self.lbry_server_port is not None: self.lbry_server_port, p = None, self.lbry_server_port + log.info('Stop listening to %s', p) return defer.maybeDeferred(p.stopListening) else: return defer.succeed(True) @@ -649,13 +650,14 @@ class Daemon(AuthJSONRPCServer): log.warn('Failed to upload log', exc_info=True) d = defer.succeed(None) d.addCallback(lambda _: self._stop_server()) + d.addErrback(log_support.failure, log, 'Failure while shutting down: %s') d.addCallback(lambda _: self._stop_reflector()) - d.addErrback(lambda err: True) + d.addErrback(log_support.failure, log, 'Failure while shutting down: %s') d.addCallback(lambda _: self.lbry_file_manager.stop()) - d.addErrback(lambda err: True) + d.addErrback(log_support.failure, log, 'Failure while shutting down: %s') if self.session is not None: d.addCallback(lambda _: self.session.shut_down()) - d.addErrback(lambda err: True) + d.addErrback(log_support.failure, log, 'Failure while shutting down: %s') return d def _update_settings(self, settings): diff --git a/packaging/osx/lbry-osx-app/lbrygui/LBRYApp.py b/packaging/osx/lbry-osx-app/lbrygui/LBRYApp.py index 3fd149fa1..787bfc8bd 100644 --- a/packaging/osx/lbry-osx-app/lbrygui/LBRYApp.py +++ b/packaging/osx/lbry-osx-app/lbrygui/LBRYApp.py @@ -66,6 +66,7 @@ class LBRYDaemonApp(AppKit.NSApplication): webbrowser.open(settings.UI_ADDRESS) def replyToApplicationShouldTerminate_(self, shouldTerminate): + log.info('Shutting down') notify("Goodbye!") reactor.stop()