use reactor.fireSystemEvent instead of reactor.stop

This commit is contained in:
Jack Robison 2017-04-30 15:50:33 -04:00
parent a9868a4f17
commit 8243349b20
5 changed files with 19 additions and 43 deletions

View file

@ -178,22 +178,7 @@ class KademliaProtocol(protocol.DatagramProtocol):
df.callback((message, address))
elif isinstance(message, msgtypes.ErrorMessage):
# The RPC request raised a remote exception; raise it locally
if message.exceptionType.startswith('exceptions.'):
exceptionClassName = message.exceptionType[11:]
else:
localModuleHierarchy = self.__module__.split('.')
remoteHierarchy = message.exceptionType.split('.')
# strip the remote hierarchy
while remoteHierarchy[0] == localModuleHierarchy[0]:
remoteHierarchy.pop(0)
localModuleHierarchy.pop(0)
exceptionClassName = '.'.join(remoteHierarchy)
remoteException = None
try:
exec 'remoteException = %s("%s")' % (exceptionClassName, message.response)
except Exception:
# We could not recreate the exception; create a generic one
remoteException = Exception(message.response)
remoteException = Exception(message.response)
df.errback(remoteException)
else:
# We got a result from the RPC

View file

@ -169,8 +169,6 @@ class Daemon(AuthJSONRPCServer):
def __init__(self, root, analytics_manager):
AuthJSONRPCServer.__init__(self, conf.settings['use_auth_http'])
reactor.addSystemEventTrigger('before', 'shutdown', self._shutdown)
self.allowed_during_startup = [
'stop', 'status', 'version',
# delete these once they are fully removed:
@ -239,6 +237,8 @@ class Daemon(AuthJSONRPCServer):
@defer.inlineCallbacks
def setup(self, launch_ui):
reactor.addSystemEventTrigger('before', 'shutdown', self._shutdown)
self._modify_loggly_formatter()
@defer.inlineCallbacks
@ -1281,6 +1281,7 @@ class Daemon(AuthJSONRPCServer):
"""
return self.jsonrpc_daemon_stop()
@defer.inlineCallbacks
def jsonrpc_daemon_stop(self):
"""
Stop lbrynet-daemon
@ -1289,13 +1290,10 @@ class Daemon(AuthJSONRPCServer):
(string) Shutdown message
"""
def _display_shutdown_message():
log.info("Shutting down lbrynet daemon")
d = self._shutdown()
d.addCallback(lambda _: _display_shutdown_message())
d.addCallback(lambda _: reactor.callLater(0.0, reactor.stop))
return self._render_response("Shutting down")
log.info("Shutting down lbrynet daemon")
response = yield self._render_response("Shutting down")
reactor.callLater(0.1, reactor.fireSystemEvent, "shutdown")
defer.returnValue(response)
@defer.inlineCallbacks
def jsonrpc_file_list(self, **kwargs):

View file

@ -120,22 +120,15 @@ def start_server_and_listen(launchui, use_auth, analytics_manager, max_tries=5):
analytics_manager: to send analytics
"""
analytics_manager.send_server_startup()
tries = 1
while tries < max_tries:
log.info('Making attempt %s / %s to startup', tries, max_tries)
try:
daemon_server = DaemonServer(analytics_manager)
yield daemon_server.start(use_auth, launchui)
analytics_manager.send_server_startup_success()
break
except Exception as e:
log.exception('Failed to startup')
yield daemon_server.stop()
analytics_manager.send_server_startup_error(str(e))
tries += 1
else:
log.warn("Exceeded max tries to start up, stopping")
reactor.callFromThread(reactor.stop)
daemon_server = DaemonServer(analytics_manager)
try:
yield daemon_server.start(use_auth, launchui)
analytics_manager.send_server_startup_success()
except Exception as e:
log.exception('Failed to startup')
yield daemon_server.stop()
analytics_manager.send_server_startup_error(str(e))
reactor.fireSystemEvent("shutdown")
if __name__ == "__main__":

View file

@ -55,6 +55,7 @@ class DaemonServer(object):
if self.server_port is not None:
yield self.server_port.stopListening()
def get_site_base(use_auth, root):
if use_auth:
log.info("Using authenticated API")

View file

@ -2,7 +2,7 @@ import time
import requests
import logging
import json
from twisted.internet import defer, threads, reactor
from twisted.internet import defer, threads
from twisted.internet.task import LoopingCall
from lbrynet import conf
@ -167,7 +167,6 @@ def get_default_market_feed(currency_pair):
class ExchangeRateManager(object):
def __init__(self):
reactor.addSystemEventTrigger('before', 'shutdown', self.stop)
self.market_feeds = [
get_default_market_feed(currency_pair) for currency_pair in CURRENCY_PAIRS]