[h5py] 419/455: Basic framework for threaded exceptions

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:57 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 6ba29ab4e28c8ef21ec437aa5f343bddd9605028
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Sat Feb 20 21:44:14 2010 +0000

    Basic framework for threaded exceptions
---
 h5py/_stub.py | 16 ++++++++++++++++
 h5py/h5e.pyx  | 25 +++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/h5py/_stub.py b/h5py/_stub.py
index 8e76381..8db41fc 100644
--- a/h5py/_stub.py
+++ b/h5py/_stub.py
@@ -12,3 +12,19 @@ def generate_class(cls1, cls2):
     HybridClass.__name__ = cls2.__name__
     return HybridClass
 
+def _exc(func):
+    """ Enable native HDF5 exception handling on this function """
+    import functools
+    from h5e import capture_errors, release_errors
+
+    def _exception_proxy(*args, **kwds):
+        capture_errors()
+        try:
+            return func(*args, **kwds)
+        finally:
+            release_errors()
+
+    functools.update_wrapper(_exception_proxy, func)
+    return _exception_proxy
+
+
diff --git a/h5py/h5e.pyx b/h5py/h5e.pyx
index a83e601..2121e9c 100644
--- a/h5py/h5e.pyx
+++ b/h5py/h5e.pyx
@@ -402,5 +402,30 @@ cdef void enable_errors(err_cookie cookie) except *:
     if(retval < 0):
         raise RuntimeError("Cant' re-enable exception support")
 
+cdef int capture_count
+cdef H5E_auto_t backup_func
+cdef void* backup_data
+
+cpdef int capture_errors() except -1:
+    global backup_func, backup_data, capture_count
+    if capture_count != 0:
+        capture_count += 1
+        return 0
+    if(H5Eget_auto(&backup_func, &backup_data)<0):
+        raise RuntimeError("Can't back up exception information")
+    if(H5Eset_auto(err_callback, NULL)<0):
+        raise RuntimeError("Can't install exception handler")
+    return 0
+
+cpdef int release_errors() except -1:
+    global backup_func, backup_data, capture_count
+    if capture_count == 0:
+        raise RuntimeError("Illegal call to release_errors")
+    capture_count -= 1
+    if capture_count == 0:
+        if(H5Eset_auto(backup_func, backup_data)<0):
+            raise RuntimeError("Can't re-install previous error handler")
+    return 0
+
 
 

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