[h5py] 87/455: Fix broken threading code

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:20 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 2c7309a9b49c12fcf7bd62f7147a79ef94a81fff
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Tue Jul 29 19:02:46 2008 +0000

    Fix broken threading code
---
 h5py/h5.pyx                |  4 ++--
 h5py/tests/test_threads.py | 21 ++++++++++++++-------
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/h5py/h5.pyx b/h5py/h5.pyx
index ee9e2cd..e1403f1 100644
--- a/h5py/h5.pyx
+++ b/h5py/h5.pyx
@@ -82,7 +82,7 @@ cdef class H5PYConfig:
     def __init__(self):
         self._complex_names = ('r','i')
         self.compile_opts = {'IO_NONBLOCK': H5PY_NONBLOCK}
-        self.lock = threading.RLock()  # Use the property to double-check its behavior
+        self._lock = threading.RLock()
 
     property lock:
         """ Reentrant lock for threading (default is threading.RLock()).
@@ -92,7 +92,7 @@ cdef class H5PYConfig:
             also MUST be reentrant, or dataset reads/writes will deadlock.
         """
         def __get__(self):
-            return self._rlock_type
+            return self._lock
 
         def __set__(self, val):
             if not (hasattr(val, 'acquire') and hasattr(val, 'release') and\
diff --git a/h5py/tests/test_threads.py b/h5py/tests/test_threads.py
index 9411482..d70bf49 100644
--- a/h5py/tests/test_threads.py
+++ b/h5py/tests/test_threads.py
@@ -79,13 +79,13 @@ class TestThreads(unittest.TestCase):
 
         self.fname = tempfile.mktemp('.hdf5')
         self.f = File(self.fname, 'w')
-        self.old_lock = h5py.config.RLock
-        h5py.config.RLock = LOCKTYPE
+        self.old_lock = h5py.config.lock
+        h5py.config.lock = LOCKTYPE()
 
     def tearDown(self):
         self.f.close()
         os.unlink(self.fname)
-        h5py.config.RLock = self.old_lock
+        h5py.config.lock = self.old_lock
 
     def test_hl_pos(self):
 
@@ -119,10 +119,10 @@ class TestThreads(unittest.TestCase):
 
     def test_hl_neg(self):
 
-        oldlock = h5py.config.RLock
+        oldlock = h5py.config.lock
         try:
             # Force the threads to operate in reverse order, by defeating locks
-            h5py.config.RLock = dummy_threading.RLock
+            h5py.config.lock = dummy_threading.RLock()
             
             reclist = []
 
@@ -152,7 +152,7 @@ class TestThreads(unittest.TestCase):
             self.assertEqual(reclist, ['D','C','B','A'])
             self.assert_(numpy.all(dset.value == numpy.ones(SHAPE)*1.0))
         finally:
-            h5py.config.RLock = oldlock
+            h5py.config.lock = oldlock
 
     def test_nonblock(self):
         # Ensure low-level I/O blocking behavior
@@ -193,12 +193,19 @@ class TestThreads(unittest.TestCase):
             writethread.start()
             time.sleep(2)       # give it more than enough time to finish, if it ignores the lock
             exit_lock_time = time.time()
-        time.sleep(0.1)
+            time.sleep(2)
         writethread.join()
 
         if h5py.config.compile_opts['IO_NONBLOCK']:
+            # With non-blocking I/O, the library will double-check that the
+            # global lock isn't held, to prevent more than one thread from
+            # calling into the HDF5 API.
             self.assert_(writethread.timestop > exit_lock_time)
         else:
+            # In blocking mode, the GIL ensures that only one thread at a time
+            # can access the HDF5 library.  Therefore the library ignores the
+            # state of the soft lock.  If this were a real program, the author
+            # of "writethread" should acquire the lock first.
             self.assert_(writethread.timestop < exit_lock_time)
 
 

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