URI: 
       tinterface: do not connect inside the constructor - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 82531131ee6c0d588a3425ac16714f08d6399f45
   DIR parent 4fbd2ea66e6a50b701ad34ec877f585155331069
  HTML Author: thomasv <thomasv@gitorious>
       Date:   Mon, 22 Oct 2012 12:58:57 +0200
       
       interface: do not connect inside the constructor
       
       Diffstat:
         M electrum                            |       6 ++++--
         M lib/gui_qt.py                       |       2 ++
         M lib/interface.py                    |      13 +++++++++----
         M scripts/servers                     |       2 +-
       
       4 files changed, 16 insertions(+), 7 deletions(-)
       ---
   DIR diff --git a/electrum b/electrum
       t@@ -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
   DIR diff --git a/lib/gui_qt.py b/lib/gui_qt.py
       t@@ -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)
        
   DIR diff --git a/lib/interface.py b/lib/interface.py
       t@@ -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')
       t@@ -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 = {}
       t@@ -319,7 +319,6 @@ class Interface(threading.Thread):
        
                self.callbacks = {}
                self.lock = threading.Lock()
       -        self.init_interface()
        
        
        
       t@@ -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')
       t@@ -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()
        
        
        
   DIR diff --git a/scripts/servers b/scripts/servers
       t@@ -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: