[PATCH 5/4] instancelimitedsems does not need a lock but must be used with global

Nicolas Sebrecht nicolas.s-dev at laposte.net
Tue May 17 02:57:03 BST 2016


Signed-off-by: Nicolas Sebrecht <nicolas.s-dev at laposte.net>
---
 offlineimap/threadutil.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/offlineimap/threadutil.py b/offlineimap/threadutil.py
index 7ad8ca4..894fd15 100644
--- a/offlineimap/threadutil.py
+++ b/offlineimap/threadutil.py
@@ -222,16 +222,16 @@ class ExitNotifyThread(Thread):
 ######################################################################
 
 instancelimitedsems = {}
-instancelimitedlock = Lock()
 
 def initInstanceLimit(instancename, instancemax):
     """Initialize the instance-limited thread implementation to permit
     up to intancemax threads with the given instancename."""
 
-    instancelimitedlock.acquire()
+    global instancelimitedsems
+
     if not instancename in instancelimitedsems:
         instancelimitedsems[instancename] = BoundedSemaphore(instancemax)
-    instancelimitedlock.release()
+
 
 class InstanceLimitedThread(ExitNotifyThread):
     def __init__(self, instancename, *args, **kwargs):
@@ -239,10 +239,14 @@ class InstanceLimitedThread(ExitNotifyThread):
         super(InstanceLimitedThread, self).__init__(*args, **kwargs)
 
     def start(self):
+        global instancelimitedsems
+
         instancelimitedsems[self.instancename].acquire()
         ExitNotifyThread.start(self)
 
     def run(self):
+        global instancelimitedsems
+
         try:
             ExitNotifyThread.run(self)
         finally:
-- 
2.7.4





More information about the OfflineIMAP-project mailing list