[h5py] 331/455: Improve locking granularity

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:47 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to annotated tag 1.3.0
in repository h5py.

commit 5671712ce01e13daaf392882be63cf44936ee4d4
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Tue Dec 1 04:54:55 2009 +0000

    Improve locking granularity
---
 h5py/highlevel.py | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/h5py/highlevel.py b/h5py/highlevel.py
index 642d0f5..2fce40e 100644
--- a/h5py/highlevel.py
+++ b/h5py/highlevel.py
@@ -70,14 +70,27 @@ def is_hdf5(fname):
 
 # === Base classes ============================================================
 
+import weakref
+
 class _LockableObject(object):
 
     """
-        Base class which provides rudimentary locking support.
+        Base class which implements locking.  Locks are associated with
+        file-resident HDF5 objects.   Requires an identifier be associated
+        with the object ("obj.id" -> ObjectID instance).
     """
 
-    _lock = threading.RLock()
+    _locks_dict = weakref.WeakKeyDictionary()
 
+    @property
+    def _lock(self):
+        # We do this in a property as opposed to the constructor because
+        # it's not clear when obj.id is set.
+        try:
+            return self._locks_dict[self.id]
+        except KeyError:
+            # MUST be setdefault to avoid race condition
+            return self._locks_dict.setdefault(self.id, threading.RLock())
 
 class HLObject(_LockableObject):
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/h5py.git



More information about the debian-science-commits mailing list