commit f6f7113978f2e21c44b1678e4b4f45ab2e0c392c
parent 7c7722439bfe29a9efeb74c6c57474d7e6cdfc1a
Author: Neil Booth <kyuupichan@gmail.com>
Date: Sun, 31 Jan 2016 10:58:27 +0900
daemon: create network inside constructor
Diffstat:
2 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/electrum b/electrum
@@ -328,12 +328,7 @@ 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 = Daemon(config)
daemon.start()
gui = init_gui(config, daemon, plugins)
daemon.gui = gui
@@ -351,12 +346,10 @@ 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()
diff --git a/lib/daemon.py b/lib/daemon.py
@@ -21,6 +21,7 @@ import ast, os
import jsonrpclib
from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer, SimpleJSONRPCRequestHandler
+from network import Network
from util import json_decode, DaemonThread
from wallet import WalletStorage, Wallet
from wizard import WizardBase
@@ -62,10 +63,14 @@ 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 config.get('offline'):
+ self.network = None
+ else:
+ self.network = Network(config)
+ self.network.start()
self.gui = None
self.wallets = {}
self.wallet = None