From f3774343db3a20bd1ee2db70361fdeab744e5017 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Wed, 4 May 2011 16:45:28 +0200 Subject: [PATCH] If we loop, exit the account synchronization after 3 failed attempts This should get rid of intermittent network failures, but lets us bail out on permanent errors. Signed-off-by: Sebastian Spaeth Signed-off-by: Nicolas Sebrecht --- offlineimap/accounts.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py index b76b48c..0eb49dc 100644 --- a/offlineimap/accounts.py +++ b/offlineimap/accounts.py @@ -202,8 +202,8 @@ class SyncableAccount(Account): self.localrepos = Repository(self, 'local') self.statusrepos = Repository(self, 'status') - # Loop account synchronization if needed - looping = True + # Loop account sync if needed (bail out after 3 failures) + looping = 3 while looping: try: try: @@ -214,16 +214,20 @@ class SyncableAccount(Account): self.ui.warn(e.reason) #stop looping and bubble up Exception if needed if e.severity >= OfflineImapError.ERROR.REPO: - looping = 0 - if e.severity > OfflineImapError.ERROR.REPO: + if looping: + looping -= 1 + if e.severity >= OfflineImapError.ERROR.CRITICAL: raise except: self.ui.warn("Error occured attempting to sync "\ "account '%s':\n"% (self, traceback.format_exc())) + else: + # after success sync, reset the looping counter to 3 + if self.refreshperiod: + looping = 3 finally: - looping = looping and \ - self.refreshperiod and \ - self.sleeper(siglistener) != 2 + if self.sleeper(siglistener) >= 2: + looping = 0 self.ui.acctdone(self.name)