[Erp5-report] r29082 - /erp5/trunk/products/ERP5/Tool/IdTool.py

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Sep 17 07:59:27 CEST 2009


Author: vincent
Date: Thu Sep 17 07:59:26 2009
New Revision: 29082

URL: http://svn.erp5.org?rev=29082&view=rev
Log:
It is pointless to instantiate a lock as a local value, as function local values are local to any given call, hence local to a thread.
Moreover, there is no need to lock access to a persistent object, as its access is protected by ACID.

Modified:
    erp5/trunk/products/ERP5/Tool/IdTool.py

Modified: erp5/trunk/products/ERP5/Tool/IdTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Tool/IdTool.py?rev=29082&r1=29081&r2=29082&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Tool/IdTool.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Tool/IdTool.py [utf8] Thu Sep 17 07:59:26 2009
@@ -35,8 +35,6 @@
 from Products.CMFCore.utils import getToolByName
 from zLOG import LOG, WARNING
 from Products.ERP5 import _dtmldir
-
-import threading
 
 from BTrees.Length import Length
 
@@ -77,12 +75,7 @@
     if getattr(aq_base(self), 'dict_ids', None) is None:
       self.dict_ids = PersistentMapping()
     if id_group is not None and id_group!='None':
-      l = threading.Lock()
-      l.acquire()
-      try:
-        self.dict_ids[id_group] = new_id
-      finally:
-        l.release()
+      self.dict_ids[id_group] = new_id
         
   security.declareProtected(Permissions.AccessContentsInformation,
                             'generateNewId')
@@ -98,31 +91,26 @@
     if id_group is not None and id_group!='None':
       # Getting the last id
       last_id = None
-      l = threading.Lock()
-      l.acquire()
-      try:
-        class Dummy:
-          pass
-        dummy = Dummy()
-        last_id = self.dict_ids.get(id_group, dummy)
-        if last_id is dummy:
-          if default is None:
-            new_id=0
-          else:
-            new_id=default
-          if method is not None:
-            new_id=method(new_id)  
-        else:
-          # Now generate a new id
-          if method is not None:
-            new_id = method(last_id)
-          else:
-            new_id = last_id + 1
- 
-        # Store the new value
-        self.dict_ids[id_group] = new_id
-      finally:
-        l.release()
+      class Dummy:
+	pass
+      dummy = Dummy()
+      last_id = self.dict_ids.get(id_group, dummy)
+      if last_id is dummy:
+	if default is None:
+	  new_id=0
+	else:
+	  new_id=default
+	if method is not None:
+	  new_id=method(new_id)  
+      else:
+	# Now generate a new id
+	if method is not None:
+	  new_id = method(last_id)
+	else:
+	  new_id = last_id + 1
+
+      # Store the new value
+      self.dict_ids[id_group] = new_id
 
     return new_id
 




More information about the Erp5-report mailing list