From d2e183fa0d95de778f9f190b75f742c3b3d16afe Mon Sep 17 00:00:00 2001 From: Vincent Pelletier <vincent@nexedi.com> Date: Thu, 17 Sep 2009 05:59:26 +0000 Subject: [PATCH] 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. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29082 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/Tool/IdTool.py | 54 +++++++++++++++---------------------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/product/ERP5/Tool/IdTool.py b/product/ERP5/Tool/IdTool.py index 3e5794886c..de765e0d1c 100644 --- a/product/ERP5/Tool/IdTool.py +++ b/product/ERP5/Tool/IdTool.py @@ -36,8 +36,6 @@ from Products.CMFCore.utils import getToolByName from zLOG import LOG, WARNING from Products.ERP5 import _dtmldir -import threading - from BTrees.Length import Length class IdTool(BaseTool): @@ -77,12 +75,7 @@ class IdTool(BaseTool): 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 @@ class IdTool(BaseTool): 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 -- 2.30.9