URI: 
       tMerge pull request #1193 from kyuupichan/if-cleanup4 - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 583d36a763090e175d720138d42def0e51411980
   DIR parent 3b357b6a6de7ff02c99328ec2a91679ca71c1788
  HTML Author: ThomasV <electrumdev@gmail.com>
       Date:   Tue,  5 May 2015 14:35:03 +0200
       
       Merge pull request #1193 from kyuupichan/if-cleanup4
       
       Move ping functionality into its own function.
       Diffstat:
         M lib/interface.py                    |      27 +++++++++++++++------------
       
       1 file changed, 15 insertions(+), 12 deletions(-)
       ---
   DIR diff --git a/lib/interface.py b/lib/interface.py
       t@@ -63,6 +63,7 @@ class TcpInterface(threading.Thread):
                self.unanswered_requests = {}
                # are we waiting for a pong?
                self.is_ping = False
       +        self.ping_time = 0
                # parse server
                self.server = server
                self.host, self.port, self.protocol = self.server.split(':')
       t@@ -276,6 +277,17 @@ class TcpInterface(threading.Thread):
                self.connected = False
                self.print_error("stopped")
        
       +    def maybe_ping(self):
       +        # ping the server with server.version?
       +        if time.time() - self.ping_time > 60:
       +            if self.is_ping:
       +                self.print_error("ping timeout")
       +                self.stop()
       +            else:
       +                self.send_request({'method':'server.version', 'params':[ELECTRUM_VERSION, PROTOCOL_VERSION]})
       +                self.is_ping = True
       +                self.ping_time = time.time()
       +
            def run(self):
                self.s = self.get_socket()
                if self.s:
       t@@ -288,21 +300,12 @@ class TcpInterface(threading.Thread):
                if not self.connected:
                    return
        
       -        # ping timer
       -        ping_time = 0
                # request timer
                request_time = False
                while self.connected:
       -            # ping the server with server.version
       -            if time.time() - ping_time > 60:
       -                if self.is_ping:
       -                    self.print_error("ping timeout")
       -                    self.connected = False
       -                    break
       -                else:
       -                    self.send_request({'method':'server.version', 'params':[ELECTRUM_VERSION, PROTOCOL_VERSION]})
       -                    self.is_ping = True
       -                    ping_time = time.time()
       +            self.maybe_ping()
       +            if not self.connected:
       +                break
                    try:
                        response = self.pipe.get()
                    except util.timeout: