[h5py] 332/455: Per-file locking

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 ae473138945dc0b47a6f0d14574d68f34f9b2c16
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Tue Dec 1 06:20:25 2009 +0000

    Per-file locking
---
 h5py/highlevel.py | 36 ++++++++++++------------------------
 1 file changed, 12 insertions(+), 24 deletions(-)

diff --git a/h5py/highlevel.py b/h5py/highlevel.py
index 2fce40e..5c38253 100644
--- a/h5py/highlevel.py
+++ b/h5py/highlevel.py
@@ -70,29 +70,7 @@ def is_hdf5(fname):
 
 # === Base classes ============================================================
 
-import weakref
-
-class _LockableObject(object):
-
-    """
-        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).
-    """
-
-    _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):
+class HLObject(object):
 
     """
         Base class for high-level interface objects.
@@ -136,6 +114,10 @@ class HLObject(_LockableObject):
         else:
             raise ValueError("Parent of an anonymous object is undefined")
 
+    @property
+    def _lock(self):
+        return self.file._fidlock
+
     def ref(self, path=None, selection=None):
         """Create an object reference
         """
@@ -679,6 +661,7 @@ class File(Group):
         else:
             raise ValueError("Invalid mode; must be one of r, r+, w, w-, a")
 
+        self._fidlock = threading.RLock()
         self.id = self.fid  # So the Group constructor can find it.
         Group.__init__(self, self, '/')
 
@@ -1158,7 +1141,7 @@ class Dataset(HLObject):
             except Exception:
                 return "<Closed HDF5 dataset>"
 
-class AttributeManager(_LockableObject, _DictCompat):
+class AttributeManager(_DictCompat):
 
     """ Allows dictionary-style access to an HDF5 object's attributes.
 
@@ -1182,6 +1165,11 @@ class AttributeManager(_LockableObject, _DictCompat):
         """ Private constructor.
         """
         self.id = parent.id
+        self._file = parent.file
+
+    @property
+    def _lock(self):
+        return self._file._fidlock
 
     def __getitem__(self, name):
         """ Read the value of an attribute.

-- 
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