[PATCH] Remove thread Lock() when saving UIDvalidity

Sebastian Spaeth Sebastian at SSpaeth.de
Sun Mar 6 10:17:12 GMT 2011


Removing this lock makes the function not threadsafe, but then it is
only ever called from one thread, the main account syncer. Also, it
doesn't make it worse than most of the other functions in that class
which are also not threadsafe.

Removing this makes the code simpler, and removes the need to import the
threading module.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
This is not critical, and has been based on current 'next' branch.

 offlineimap/folder/Base.py |   28 +++++++++++++++-------------
 1 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py
index 8e6a6b3..5238f1e 100644
--- a/offlineimap/folder/Base.py
+++ b/offlineimap/folder/Base.py
@@ -16,7 +16,6 @@
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
-from threading import *
 from offlineimap import threadutil
 from offlineimap.ui import getglobalui
 import os.path
@@ -26,7 +25,6 @@ import traceback
 
 class BaseFolder:
     def __init__(self):
-        self.uidlock = Lock()
         self.ui = getglobalui()
         
     def getname(self):
@@ -83,6 +81,11 @@ class BaseFolder:
         return foldername
 
     def isuidvalidityok(self):
+        """Does the cached UID match the real UID
+
+        If required it caches the UID. In this case the function is not
+        threadsafe. So don't attempt to call it from concurrent threads."""
+
         if self.getsaveduidvalidity() != None:
             return self.getsaveduidvalidity() == self.getuidvalidity()
         else:
@@ -106,17 +109,18 @@ class BaseFolder:
         return self._base_saved_uidvalidity
 
     def saveuidvalidity(self):
+        """Save the UID value of the folder to the status
+
+        This function is not threadsafe, so don't attempt to call it
+        from concurrent threads."""
         newval = self.getuidvalidity()
         uidfilename = self._getuidfilename()
-        self.uidlock.acquire()
-        try:
-            file = open(uidfilename + ".tmp", "wt")
-            file.write("%d\n" % newval)
-            file.close()
-            os.rename(uidfilename + ".tmp", uidfilename)
-            self._base_saved_uidvalidity = newval
-        finally:
-            self.uidlock.release()
+
+        file = open(uidfilename + ".tmp", "wt")
+        file.write("%d\n" % newval)
+        file.close()
+        os.rename(uidfilename + ".tmp", uidfilename)
+        self._base_saved_uidvalidity = newval
 
     def getuidvalidity(self):
         raise NotImplementedException
@@ -425,5 +429,3 @@ class BaseFolder:
         except:
             self.ui.warn("ERROR attempting to sync flags " \
                 + "for account " + self.getaccountname() + ":" + traceback.format_exc())
-        
-            
-- 
1.7.1





More information about the OfflineIMAP-project mailing list