From 3cb2ddccb897cfd1d6bcb4a2b9393040b899bd3e Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Fri, 31 Aug 2012 22:34:53 +0200 Subject: [PATCH] Use "with lock" pattern While looking at the code to investigate if an why we sometimes don't seem to honor the write lock, I made it use the more modern "with lock:" pattern. Still have not found out how we could ever be using 2 instances of the LocalStatusFolder for the same folder. Signed-off-by: Sebastian Spaeth --- offlineimap/folder/LocalStatus.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/offlineimap/folder/LocalStatus.py b/offlineimap/folder/LocalStatus.py index b3779fd..6f65f83 100644 --- a/offlineimap/folder/LocalStatus.py +++ b/offlineimap/folder/LocalStatus.py @@ -85,8 +85,7 @@ class LocalStatusFolder(BaseFolder): file.close() def save(self): - self.savelock.acquire() - try: + with self.savelock: file = open(self.filename + ".tmp", "wt") file.write(magicline + "\n") for msg in self.messagelist.values(): @@ -104,9 +103,6 @@ class LocalStatusFolder(BaseFolder): os.fsync(fd) os.close(fd) - finally: - self.savelock.release() - def getmessagelist(self): return self.messagelist