[PATCH v2] refactoring: simplify the semaphorewait logic

Nicolas Sebrecht nicolas.s-dev at laposte.net
Wed May 11 21:10:56 BST 2011


The semaphorewait()/waitforthread() logic is usefull for IMAP starting
connections. We actually use it in imapserver only.

This patch removes the over-engineered factorized methods. It tend to simplify
the code by cleaning out a chain of two direct calls having no other processes.

Signed-off-by: Nicolas Sebrecht <nicolas.s-dev at laposte.net>
---
 offlineimap/folder/Base.py |    5 -----
 offlineimap/imapserver.py  |    3 ++-
 offlineimap/threadutil.py  |    4 ----
 3 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py
index a5fd242..608d361 100644
--- a/offlineimap/folder/Base.py
+++ b/offlineimap/folder/Base.py
@@ -37,11 +37,6 @@ class BaseFolder(object):
         false otherwise.  Probably only IMAP will return true."""
         return 0
 
-    def waitforthread(self):
-        """For threading folders, waits until there is a resource available
-        before firing off a thread.  For all others, returns immediately."""
-        pass
-
     def getcopyinstancelimit(self):
         """For threading folders, returns the instancelimitname for
         InstanceLimitedThreads."""
diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py
index bfe3796..9adfcf3 100644
--- a/offlineimap/imapserver.py
+++ b/offlineimap/imapserver.py
@@ -301,7 +301,8 @@ class IMAPServer:
         to copy messages, then have them all wait for 3 available connections.
         It's OK if we have maxconnections + 1 or 2 threads, which is what
         this will help us do."""
-        threadutil.semaphorewait(self.semaphore)
+        self.semaphore.acquire()
+        self.semaphore.release()
 
     def close(self):
         # Make sure I own all the semaphores.  Let the threads finish
diff --git a/offlineimap/threadutil.py b/offlineimap/threadutil.py
index cef2195..1822d16 100644
--- a/offlineimap/threadutil.py
+++ b/offlineimap/threadutil.py
@@ -42,10 +42,6 @@ def semaphorereset(semaphore, originalstate):
     for i in range(originalstate):
         semaphore.release()
         
-def semaphorewait(semaphore):
-    semaphore.acquire()
-    semaphore.release()
-
 class threadlist:
     def __init__(self):
         self.lock = Lock()
-- 
1.7.5.1.354.g761178





More information about the OfflineIMAP-project mailing list