commit 0a1b3eac9cd297141f137075cc3de6abefab54a1
parent 3b445046440c9deeadc9bed016014b56bf476974
Author: Neil Booth <kyuupichan@gmail.com>
Date: Fri, 29 Jan 2016 21:51:46 +0900
Daemon network cleanup
All Daemon creation was preceded by Network creation, based on
config, and passing it to Daemon.
As config is passed to Daemon, it might as well create its own
network and the code is in one place.
Diffstat:
2 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/electrum b/electrum
@@ -328,14 +328,8 @@ if __name__ == '__main__':
if server is not None:
result = server.gui(config_options)
else:
- if not config.get('offline'):
- network = Network(config)
- network.start()
- else:
- network = None
- daemon = Daemon(config, network)
- daemon.start()
- gui = init_gui(config, network, daemon, plugins)
+ daemon = Daemon(config)
+ gui = init_gui(config, daemon.network, daemon, plugins)
daemon.gui = gui
gui.main()
sys.exit(0)
@@ -351,15 +345,12 @@ if __name__ == '__main__':
elif subcommand == 'start':
p = os.fork()
if p == 0:
- network = Network(config)
- network.start()
- daemon = Daemon(config, network)
+ daemon = Daemon(config)
if config.get('websocket_server'):
from electrum import websockets
- websockets.WebSocketServer(config, network).start()
+ websockets.WebSocketServer(config, daemon.network).start()
if config.get('requests_dir'):
util.check_www_dir(config.get('requests_dir'))
- daemon.start()
daemon.join()
sys.exit(0)
else:
diff --git a/lib/daemon.py b/lib/daemon.py
@@ -26,7 +26,7 @@ from wallet import WalletStorage, Wallet
from wizard import WizardBase
from commands import known_commands, Commands
from simple_config import SimpleConfig
-
+from network import Network
def lockfile(config):
return os.path.join(config.path, 'daemon')
@@ -62,10 +62,16 @@ class RequestHandler(SimpleJSONRPCRequestHandler):
class Daemon(DaemonThread):
- def __init__(self, config, network):
+ def __init__(self, config):
DaemonThread.__init__(self)
self.config = config
- self.network = network
+ if not config.get('offline'):
+ self.network = Network(config)
+ self.network.start()
+ else:
+ # FIXME: some of the daemon code assumes self.network is not None
+ # This is not something this change has introduced
+ self.network = None
self.gui = None
self.wallets = {}
self.wallet = None
@@ -82,6 +88,7 @@ class Daemon(DaemonThread):
self.server.register_function(self.ping, 'ping')
self.server.register_function(self.run_daemon, 'daemon')
self.server.register_function(self.run_gui, 'gui')
+ self.start()
def ping(self):
return True