use reactor.fireSystemEvent instead of reactor.stop
This commit is contained in:
parent
a9868a4f17
commit
8243349b20
5 changed files with 19 additions and 43 deletions
|
@ -178,22 +178,7 @@ class KademliaProtocol(protocol.DatagramProtocol):
|
||||||
df.callback((message, address))
|
df.callback((message, address))
|
||||||
elif isinstance(message, msgtypes.ErrorMessage):
|
elif isinstance(message, msgtypes.ErrorMessage):
|
||||||
# The RPC request raised a remote exception; raise it locally
|
# The RPC request raised a remote exception; raise it locally
|
||||||
if message.exceptionType.startswith('exceptions.'):
|
remoteException = Exception(message.response)
|
||||||
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)
|
|
||||||
df.errback(remoteException)
|
df.errback(remoteException)
|
||||||
else:
|
else:
|
||||||
# We got a result from the RPC
|
# We got a result from the RPC
|
||||||
|
|
|
@ -169,8 +169,6 @@ class Daemon(AuthJSONRPCServer):
|
||||||
|
|
||||||
def __init__(self, root, analytics_manager):
|
def __init__(self, root, analytics_manager):
|
||||||
AuthJSONRPCServer.__init__(self, conf.settings['use_auth_http'])
|
AuthJSONRPCServer.__init__(self, conf.settings['use_auth_http'])
|
||||||
reactor.addSystemEventTrigger('before', 'shutdown', self._shutdown)
|
|
||||||
|
|
||||||
self.allowed_during_startup = [
|
self.allowed_during_startup = [
|
||||||
'stop', 'status', 'version',
|
'stop', 'status', 'version',
|
||||||
# delete these once they are fully removed:
|
# delete these once they are fully removed:
|
||||||
|
@ -239,6 +237,8 @@ class Daemon(AuthJSONRPCServer):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def setup(self, launch_ui):
|
def setup(self, launch_ui):
|
||||||
|
reactor.addSystemEventTrigger('before', 'shutdown', self._shutdown)
|
||||||
|
|
||||||
self._modify_loggly_formatter()
|
self._modify_loggly_formatter()
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
@ -1281,6 +1281,7 @@ class Daemon(AuthJSONRPCServer):
|
||||||
"""
|
"""
|
||||||
return self.jsonrpc_daemon_stop()
|
return self.jsonrpc_daemon_stop()
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
def jsonrpc_daemon_stop(self):
|
def jsonrpc_daemon_stop(self):
|
||||||
"""
|
"""
|
||||||
Stop lbrynet-daemon
|
Stop lbrynet-daemon
|
||||||
|
@ -1289,13 +1290,10 @@ class Daemon(AuthJSONRPCServer):
|
||||||
(string) Shutdown message
|
(string) Shutdown message
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _display_shutdown_message():
|
log.info("Shutting down lbrynet daemon")
|
||||||
log.info("Shutting down lbrynet daemon")
|
response = yield self._render_response("Shutting down")
|
||||||
|
reactor.callLater(0.1, reactor.fireSystemEvent, "shutdown")
|
||||||
d = self._shutdown()
|
defer.returnValue(response)
|
||||||
d.addCallback(lambda _: _display_shutdown_message())
|
|
||||||
d.addCallback(lambda _: reactor.callLater(0.0, reactor.stop))
|
|
||||||
return self._render_response("Shutting down")
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def jsonrpc_file_list(self, **kwargs):
|
def jsonrpc_file_list(self, **kwargs):
|
||||||
|
|
|
@ -120,22 +120,15 @@ def start_server_and_listen(launchui, use_auth, analytics_manager, max_tries=5):
|
||||||
analytics_manager: to send analytics
|
analytics_manager: to send analytics
|
||||||
"""
|
"""
|
||||||
analytics_manager.send_server_startup()
|
analytics_manager.send_server_startup()
|
||||||
tries = 1
|
daemon_server = DaemonServer(analytics_manager)
|
||||||
while tries < max_tries:
|
try:
|
||||||
log.info('Making attempt %s / %s to startup', tries, max_tries)
|
yield daemon_server.start(use_auth, launchui)
|
||||||
try:
|
analytics_manager.send_server_startup_success()
|
||||||
daemon_server = DaemonServer(analytics_manager)
|
except Exception as e:
|
||||||
yield daemon_server.start(use_auth, launchui)
|
log.exception('Failed to startup')
|
||||||
analytics_manager.send_server_startup_success()
|
yield daemon_server.stop()
|
||||||
break
|
analytics_manager.send_server_startup_error(str(e))
|
||||||
except Exception as e:
|
reactor.fireSystemEvent("shutdown")
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -55,6 +55,7 @@ class DaemonServer(object):
|
||||||
if self.server_port is not None:
|
if self.server_port is not None:
|
||||||
yield self.server_port.stopListening()
|
yield self.server_port.stopListening()
|
||||||
|
|
||||||
|
|
||||||
def get_site_base(use_auth, root):
|
def get_site_base(use_auth, root):
|
||||||
if use_auth:
|
if use_auth:
|
||||||
log.info("Using authenticated API")
|
log.info("Using authenticated API")
|
||||||
|
|
|
@ -2,7 +2,7 @@ import time
|
||||||
import requests
|
import requests
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
from twisted.internet import defer, threads, reactor
|
from twisted.internet import defer, threads
|
||||||
from twisted.internet.task import LoopingCall
|
from twisted.internet.task import LoopingCall
|
||||||
|
|
||||||
from lbrynet import conf
|
from lbrynet import conf
|
||||||
|
@ -167,7 +167,6 @@ def get_default_market_feed(currency_pair):
|
||||||
|
|
||||||
class ExchangeRateManager(object):
|
class ExchangeRateManager(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
reactor.addSystemEventTrigger('before', 'shutdown', self.stop)
|
|
||||||
self.market_feeds = [
|
self.market_feeds = [
|
||||||
get_default_market_feed(currency_pair) for currency_pair in CURRENCY_PAIRS]
|
get_default_market_feed(currency_pair) for currency_pair in CURRENCY_PAIRS]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue