Browse Source

interface: do not connect inside the constructor

283
thomasv 12 years ago
parent
commit
82531131ee
  1. 6
      electrum
  2. 2
      lib/gui_qt.py
  3. 13
      lib/interface.py
  4. 2
      scripts/servers

6
electrum

@ -184,15 +184,17 @@ if __name__ == '__main__':
else:
sys.exit("Error: Unknown GUI: " + pref_gui )
gui = gui.ElectrumGui(wallet, config)
interface = Interface(config, True)
interface.register_callback('peers', gui.server_list_changed)
interface.start()
wallet.interface = interface
gui = gui.ElectrumGui(wallet, config)
interface.register_callback('peers', gui.server_list_changed)
# need to wait until interface is connected..
WalletSynchronizer(wallet, config).start()
WalletVerifier(wallet, config).start()
try:
found = config.wallet_file_exists
if not found:

2
lib/gui_qt.py

@ -208,6 +208,8 @@ class ElectrumWindow(QMainWindow):
self.wallet = wallet
self.config = config
self.wallet.interface.register_callback('updated', self.update_callback)
self.wallet.interface.register_callback('connected', self.update_callback)
self.wallet.interface.register_callback('disconnected', self.update_callback)
self.detailed_view = config.get('qt_detailed_view', False)

13
lib/interface.py

@ -266,7 +266,6 @@ class Interface(threading.Thread):
self.bytes_received += len(msg)
if msg == '':
self.is_connected = False
print "Disconnected."
while True:
s = out.find('\n')
@ -312,6 +311,7 @@ class Interface(threading.Thread):
self.daemon = True
self.loop = loop
self.config = config
self.connect_event = threading.Event()
self.subscriptions = {}
self.responses = {}
@ -319,7 +319,6 @@ class Interface(threading.Thread):
self.callbacks = {}
self.lock = threading.Lock()
self.init_interface()
@ -339,6 +338,7 @@ class Interface(threading.Thread):
if not servers:
raise BaseException('no server available')
self.connect_event.set()
if self.is_connected:
self.send([('server.version', [ELECTRUM_VERSION])])
self.trigger_callback('connected')
@ -469,16 +469,21 @@ class Interface(threading.Thread):
return out
def start(self):
threading.Thread.start(self)
# wait until connection is established
self.connect_event.wait()
def run(self):
while True:
self.init_interface()
self.resend_subscriptions()
self.run_tcp() if self.protocol in 'st' else self.run_http()
self.trigger_callback('disconnected')
if not self.loop: break
time.sleep(5)
self.init_interface()
self.resend_subscriptions()

2
scripts/servers

@ -5,10 +5,10 @@ import time, Queue
servers = DEFAULT_SERVERS
interfaces = map ( lambda server: Interface({'server':server} ), servers )
for i in interfaces: i.start()
for i in interfaces:
if i.is_connected:
i.start()
i.send([('blockchain.numblocks.subscribe',[])])
i.status = "timed out"
else:

Loading…
Cancel
Save