electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 82531131ee6c0d588a3425ac16714f08d6399f45
parent 4fbd2ea66e6a50b701ad34ec877f585155331069
Author: thomasv <thomasv@gitorious>
Date:   Mon, 22 Oct 2012 12:58:57 +0200

interface: do not connect inside the constructor

Diffstat:
Melectrum | 6++++--
Mlib/gui_qt.py | 2++
Mlib/interface.py | 13+++++++++----
Mscripts/servers | 2+-
4 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/electrum b/electrum @@ -184,14 +184,16 @@ 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 diff --git a/lib/gui_qt.py b/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) diff --git a/lib/interface.py b/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() diff --git a/scripts/servers b/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: