From 6c9da8aba64ad1b01fefd8c282c014c3264d7a30 Mon Sep 17 00:00:00 2001
From: TheNain38 <TheNain38@users.noreply.github.com>
Date: Thu, 14 Apr 2016 11:03:49 +0200
Subject: [PATCH] Exception handling when connecting first time

---
 plugins/Zeroname/updater/zeroname_updater.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/plugins/Zeroname/updater/zeroname_updater.py b/plugins/Zeroname/updater/zeroname_updater.py
index 1db8ddff..711ee1bc 100644
--- a/plugins/Zeroname/updater/zeroname_updater.py
+++ b/plugins/Zeroname/updater/zeroname_updater.py
@@ -144,7 +144,19 @@ if sys.platform == 'win32':
 # Initialize rpc connection
 rpc_auth, rpc_timeout = initRpc(namecoin_location + "namecoin.conf")
 rpc = AuthServiceProxy(rpc_auth, timeout=rpc_timeout)
-last_block = int(rpc.getinfo()["blocks"])
+
+while 1:
+    try:
+        time.sleep(1)
+        last_block = int(rpc.getinfo()["blocks"])
+        break # Connection succeeded
+    except socket.timeout:  # Timeout
+        print ".",
+        sys.stdout.flush()
+    except Exception, err:
+        print "Exception", err.__class__, err
+        time.sleep(5)
+        rpc = AuthServiceProxy(rpc_auth, timeout=rpc_timeout)
 
 if not config["lastprocessed"]:  # First startup: Start processing from last block
     config["lastprocessed"] = last_block