make connection more robust

This commit is contained in:
ThomasV 2011-12-13 16:58:42 +01:00
parent 9a85fd503d
commit 752761de32
1 changed files with 13 additions and 14 deletions

View File

@ -487,30 +487,33 @@ class BitcoinGUI:
def update_wallet_thread(): def update_wallet_thread():
while True: while True:
try: try:
self.is_connected = False
self.wallet.new_session() self.wallet.new_session()
self.is_connected = True self.is_connected = True
self.update_session = False self.update_session = False
self.info.set_text( self.wallet.message) self.info.set_text( self.wallet.message)
except: except:
self.is_connected = False
traceback.print_exc(file=sys.stdout) traceback.print_exc(file=sys.stdout)
time.sleep(self.period) time.sleep(self.period)
continue continue
get_servers_time = 0 get_servers_time = 0
while True: while True:
if self.is_connected and self.update_session: try:
self.wallet.update_session() if self.is_connected and self.update_session:
self.update_session = False self.wallet.update_session()
self.update_session = False
if time.time() - get_servers_time > 5*60: if time.time() - get_servers_time > 5*60:
wallet.get_servers() wallet.get_servers()
get_servers_time = time.time() get_servers_time = time.time()
self.period = 15 if self.wallet.use_http() else 5 self.period = 15 if self.wallet.use_http() else 5
try:
u = self.wallet.update() u = self.wallet.update()
self.is_connected = True if u:
self.wallet.save()
gobject.idle_add( self.update_history_tab )
time.sleep(self.period)
except BaseException: except BaseException:
print "starting new session" print "starting new session"
break break
@ -522,11 +525,7 @@ class BitcoinGUI:
print "error" print "error"
traceback.print_exc(file=sys.stdout) traceback.print_exc(file=sys.stdout)
break break
self.error = '' if self.is_connected else "Not connected" self.error = '' if self.is_connected else "Not connected"
if u:
self.wallet.save()
gobject.idle_add( self.update_history_tab )
time.sleep(self.period)
thread.start_new_thread(update_wallet_thread, ()) thread.start_new_thread(update_wallet_thread, ())
thread.start_new_thread(update_status_bar_thread, ()) thread.start_new_thread(update_status_bar_thread, ())