[h5py] 185/455: Remove no-threads option, fix decorators
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:31 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 1ba1cb4023cff19f0405f7381e3629ea73627130
Author: andrewcollette <andrew.collette at gmail.com>
Date: Thu Jan 1 21:34:14 2009 +0000
Remove no-threads option, fix decorators
---
h5py/_extras.py | 101 ------------------------------------------------------
h5py/_sync.py | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
h5py/h5.pyx | 48 ++++++++++----------------
h5py/h5a.pyx | 4 +--
h5py/h5d.pyx | 14 +++-----
h5py/h5f.pyx | 4 ++-
h5py/h5fd.pyx | 1 -
h5py/h5g.pyx | 3 +-
h5py/h5i.pyx | 2 +-
h5py/h5l.pyx | 4 ++-
h5py/h5o.pyx | 4 ++-
h5py/h5p.pyx | 3 +-
h5py/h5r.pyx | 3 +-
h5py/h5s.pyx | 4 ++-
h5py/h5t.pyx | 2 +-
h5py/h5z.pyx | 4 ++-
h5py/sync.pxi | 46 -------------------------
h5py/utils.pyx | 3 +-
setup.py | 14 ++------
19 files changed, 154 insertions(+), 213 deletions(-)
diff --git a/h5py/_extras.py b/h5py/_extras.py
deleted file mode 100644
index cafdd16..0000000
--- a/h5py/_extras.py
+++ /dev/null
@@ -1,101 +0,0 @@
-#+
-#
-# This file is part of h5py, a low-level Python interface to the HDF5 library.
-#
-# Copyright (C) 2008 Andrew Collette
-# http://h5py.alfven.org
-# License: BSD (See LICENSE.txt for full license)
-#
-# $Date$
-#
-#-
-from __future__ import with_statement
-
-import logging
-from functools import update_wrapper
-
-from h5py.h5 import get_phil
-phil = get_phil()
-
-prof = {}
-from time import time
-
-def uw_apply(wrap, func):
- # Cython methods don't have a "module" attribute for some reason
- if hasattr(func, '__module__'):
- update_wrapper(wrap, func, assigned=('__module__', '__name__', '__doc__'))
- else:
- update_wrapper(wrap, func, assigned=('__name__','__doc__'))
-
-def funcname(func):
-
- if hasattr(func, '__module__') and func.__module__ is not None:
- fullname = "%s.%s" % (func.__module__, func.__name__)
- elif hasattr(func, '__self__'):
- fullname = "%s.%s" % (func.__self__.__class__.__name__, func.__name__)
- else:
- fullname = func.__name__
-
- return fullname
-
-
-def h5sync(logger=None):
-
- if logger is None:
- def sync_simple(func):
-
- def wrap(*args, **kwds):
- with phil:
- return func(*args, **kwds)
- uw_apply(wrap, func)
- return wrap
-
- return sync_simple
-
- else:
-
- def sync_debug(func):
-
- fname = funcname(func)
-
- def wrap(*args, **kwds):
- with phil:
- logger.debug( ("[ Call %s\n%s\n%s" % (fname, args, kwds)).replace("\n", "\n ") )
- stime = time()
- try:
- retval = func(*args, **kwds)
- except Exception, e:
- logger.debug('! Exception in %s: %s("%s")' % (fname, e.__class__.__name__, e))
- raise
- otime = time()
- logger.debug( ("] Exit %s\n%s" % (fname,retval)).replace("\n", "\n ") )
- prof.setdefault(repr(func), set()).add(otime-stime)
- return retval
-
- uw_apply(wrap, func)
- return wrap
-
- return sync_debug
-
-def h5sync_dummy(logger):
-
- def log_only(func):
-
- def wrap(*args, **kwds):
- logger.debug("[ Function entry: %s" % func.__name__)
- try:
- retval = func(*args, **kwds)
- except:
- logger.debug("! Exception in %s" % func.__name__)
- raise
- logger.debug("] Function exit: %s" % func.__name__)
- return retval
- uw_apply(wrap, func)
- return wrap
-
- return log_only
-
-
-
-
-
diff --git a/h5py/_sync.py b/h5py/_sync.py
new file mode 100644
index 0000000..4e763c7
--- /dev/null
+++ b/h5py/_sync.py
@@ -0,0 +1,103 @@
+#+
+#
+# This file is part of h5py, a low-level Python interface to the HDF5 library.
+#
+# Copyright (C) 2008 Andrew Collette
+# http://h5py.alfven.org
+# License: BSD (See LICENSE.txt for full license)
+#
+# $Date$
+#
+#-
+
+from __future__ import with_statement
+
+import logging
+from functools import update_wrapper
+
+from h5py.h5 import get_phil, get_config
+
+phil = get_phil()
+config = get_config()
+logger = logging.getLogger('h5py.functions')
+
+def uw_apply(wrap, func):
+ # Cython methods don't have a "module" attribute for some reason
+ if hasattr(func, '__module__'):
+ update_wrapper(wrap, func, assigned=('__module__', '__name__', '__doc__'))
+ else:
+ update_wrapper(wrap, func, assigned=('__name__','__doc__'))
+
+def funcname(func):
+
+ if hasattr(func, '__module__') and func.__module__ is not None:
+ fullname = "%s.%s" % (func.__module__, func.__name__)
+ elif hasattr(func, '__self__'):
+ fullname = "%s.%s" % (func.__self__.__class__.__name__, func.__name__)
+ else:
+ fullname = func.__name__
+
+ return fullname
+
+if config.DEBUG:
+
+ def nosync(func):
+
+ fname = funcname(func)
+
+ def wrap(*args, **kwds):
+ logger.debug( ("[ Call %s\n%s\n%s" % (fname, args, kwds)).replace("\n", "\n ") )
+ try:
+ retval = func(*args, **kwds)
+ except BaseException, e:
+ logger.debug('! Exception in %s: %s("%s")' % (fname, e.__class__.__name__, e))
+ raise
+ logger.debug( ("] Exit %s\n%s" % (fname,retval)).replace("\n", "\n ") )
+ return retval
+ uw_apply(wrap, func)
+ return wrap
+
+ def sync(func):
+
+ func = nosync(func) #enables logging and updates __doc__, etc.
+
+ def wrap(*args, **kwds):
+ with phil:
+ return func(*args, **kwds)
+ return wrap
+
+else:
+
+ def sync(func):
+ def wrap(*args, **kwds):
+ with phil:
+ return func(*args, **kwds)
+ uw_apply(wrap, func)
+ return wrap
+
+ def nosync(func):
+ def wrap(*args, **kwds):
+ return func(*args, **kwds)
+ uw_apply(wrap, func)
+ return wrap
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/h5py/h5.pyx b/h5py/h5.pyx
index 7fbe03f..cc3e472 100644
--- a/h5py/h5.pyx
+++ b/h5py/h5.pyx
@@ -82,7 +82,6 @@ cdef class H5PYConfig:
self.API_16 = H5PY_16API
self.API_18 = H5PY_18API
self.DEBUG = H5PY_DEBUG
- self.THREADS = H5PY_THREADS
self._r_name = 'r'
self._i_name = 'i'
@@ -112,12 +111,11 @@ Summary of h5py config
HDF5: %s
1.6 API: %s
1.8 API: %s
-Thread-aware: %s
Diagnostic mode: %s
Complex names: %s"""
rstr %= ("%d.%d.%d" % get_libversion(), bool(self.API_16),
- bool(self.API_18), bool(self.THREADS), bool(self.DEBUG),
+ bool(self.API_18), bool(self.DEBUG),
self.complex_names)
return rstr
@@ -163,38 +161,26 @@ cdef class PHIL:
which manages access to the library. HDF5 is not guaranteed to
be thread-safe, and certain callbacks in h5py can execute arbitrary
threaded Python code, defeating the normal GIL-based protection for
- extension modules. Therefore, in threading mode all routines
- acquire this lock first. When h5py is built without thread awareness,
- all locking methods are no-ops.
+ extension modules. Therefore, in all routines acquire this lock first.
You should NOT use this object in your code. It's internal to the
library.
"""
- IF H5PY_THREADS:
- def __init__(self):
- self.lock = threading.RLock()
- cpdef bint __enter__(self) except -1:
- self.lock.acquire()
- return 0
- cpdef bint __exit__(self,a,b,c) except -1:
- self.lock.release()
- return 0
- cpdef bint acquire(self, int blocking=1) except -1:
- cdef bint rval = self.lock.acquire(blocking)
- return rval
- cpdef bint release(self) except -1:
- self.lock.release()
- return 0
- ELSE:
- cpdef bint __enter__(self) except -1:
- return 0
- cpdef bint __exit__(self,a,b,c) except -1:
- return 0
- cpdef bint acquire(self, int blocking=1) except -1:
- return 1
- cpdef bint release(self) except -1:
- return 0
+ def __init__(self):
+ self.lock = threading.RLock()
+ cpdef bint __enter__(self) except -1:
+ self.lock.acquire()
+ return 0
+ cpdef bint __exit__(self,a,b,c) except -1:
+ self.lock.release()
+ return 0
+ cpdef bint acquire(self, int blocking=1) except -1:
+ cdef bint rval = self.lock.acquire(blocking)
+ return rval
+ cpdef bint release(self) except -1:
+ self.lock.release()
+ return 0
cdef PHIL phil = PHIL()
@@ -208,7 +194,7 @@ cpdef PHIL get_phil():
# Everything required for the decorator is now defined
-include "sync.pxi"
+from _sync import sync, nosync
# === Public C API for object identifiers =====================================
diff --git a/h5py/h5a.pyx b/h5py/h5a.pyx
index 68e24ec..f25e233 100644
--- a/h5py/h5a.pyx
+++ b/h5py/h5a.pyx
@@ -16,8 +16,6 @@ __doc__=\
"""
include "config.pxi"
-include "sync.pxi"
-
# Compile-time imports
from h5 cimport init_hdf5, SmartStruct
@@ -31,6 +29,8 @@ from utils cimport check_numpy_read, check_numpy_write, emalloc, efree
import_array()
init_hdf5()
+# Runtime imports
+from _sync import sync, nosync
# === General attribute operations ============================================
diff --git a/h5py/h5d.pyx b/h5py/h5d.pyx
index 2108e6c..5ee35e1 100644
--- a/h5py/h5d.pyx
+++ b/h5py/h5d.pyx
@@ -14,7 +14,6 @@ __doc__ = \
Provides access to the low-level HDF5 "H5D" dataset interface.
"""
include "config.pxi"
-include "sync.pxi"
# Compile-time imports
from h5 cimport init_hdf5
@@ -29,6 +28,9 @@ from h5p cimport PropID, propwrap, pdefault
import_array()
init_hdf5()
+# Runtime imports
+from _sync import sync, nosync
+
# === Public constants and data structures ====================================
COMPACT = H5D_COMPACT
@@ -197,10 +199,7 @@ cdef class DatasetID(ObjectID):
arr_obj.flags &= (~NPY_WRITEABLE) # Wish-it-was-a-mutex approach
try:
- IF H5PY_THREADS:
- with nogil:
- H5PY_H5Dread(self_id, mtype_id, mspace_id, fspace_id, plist_id, data)
- ELSE:
+ with nogil:
H5PY_H5Dread(self_id, mtype_id, mspace_id, fspace_id, plist_id, data)
finally:
arr_obj.flags |= NPY_WRITEABLE
@@ -239,10 +238,7 @@ cdef class DatasetID(ObjectID):
arr_obj.flags &= (~NPY_WRITEABLE) # Wish-it-was-a-mutex approach
try:
- IF H5PY_THREADS:
- with nogil:
- H5PY_H5Dwrite(self_id, mtype_id, mspace_id, fspace_id, plist_id, data)
- ELSE:
+ with nogil:
H5PY_H5Dwrite(self_id, mtype_id, mspace_id, fspace_id, plist_id, data)
finally:
arr_obj.flags |= NPY_WRITEABLE
diff --git a/h5py/h5f.pyx b/h5py/h5f.pyx
index b00cd23..1027660 100644
--- a/h5py/h5f.pyx
+++ b/h5py/h5f.pyx
@@ -15,7 +15,6 @@ __doc__ = \
"""
include "config.pxi"
-include "sync.pxi"
# Compile-time imports
from h5 cimport init_hdf5
@@ -27,6 +26,9 @@ from utils cimport emalloc, efree
# Initialization
init_hdf5()
+# Runtime imports
+from _sync import sync, nosync
+
# === Public constants and data structures ====================================
ACC_TRUNC = H5F_ACC_TRUNC
diff --git a/h5py/h5fd.pyx b/h5py/h5fd.pyx
index 24aa7bc..ea8c08c 100644
--- a/h5py/h5fd.pyx
+++ b/h5py/h5fd.pyx
@@ -14,7 +14,6 @@
# licenses/hdf5.txt for the full HDF5 software license.
include "config.pxi"
-include "sync.pxi"
from h5 cimport init_hdf5
init_hdf5()
diff --git a/h5py/h5g.pyx b/h5py/h5g.pyx
index 07c5d69..d8ef26b 100644
--- a/h5py/h5g.pyx
+++ b/h5py/h5g.pyx
@@ -15,7 +15,6 @@ __doc__ = \
"""
include "config.pxi"
-include "sync.pxi"
# Compile-time imports
from h5 cimport init_hdf5, SmartStruct
@@ -29,7 +28,7 @@ init_hdf5()
# Runtime imports
from h5 import H5Error
-
+from _sync import sync, nosync
# === Public constants and data structures ====================================
diff --git a/h5py/h5i.pyx b/h5py/h5i.pyx
index 8ac3743..3d470ed 100644
--- a/h5py/h5i.pyx
+++ b/h5py/h5i.pyx
@@ -15,7 +15,6 @@ __doc__ = \
"""
include "config.pxi"
-include "sync.pxi"
# Pyrex compile-time imports
from h5 cimport init_hdf5, ObjectID
@@ -32,6 +31,7 @@ init_hdf5()
# Runtime imports
from h5 import H5Error
+from _sync import sync, nosync
# === Public constants and data structures ====================================
diff --git a/h5py/h5l.pyx b/h5py/h5l.pyx
index e37f515..0d629d7 100644
--- a/h5py/h5l.pyx
+++ b/h5py/h5l.pyx
@@ -15,7 +15,6 @@ __doc__ = \
"""
include "config.pxi"
-include "sync.pxi"
from h5 cimport init_hdf5, SmartStruct
from h5p cimport PropID, pdefault
@@ -25,6 +24,9 @@ from python_exc cimport PyErr_SetString
init_hdf5()
+# Runtime imports
+from _sync import sync, nosync
+
# === Public constants ========================================================
TYPE_HARD = H5L_TYPE_HARD
diff --git a/h5py/h5o.pyx b/h5py/h5o.pyx
index 6dbd188..75e2fee 100644
--- a/h5py/h5o.pyx
+++ b/h5py/h5o.pyx
@@ -11,7 +11,6 @@
#-
include "config.pxi"
-include "sync.pxi"
# Module for the new "H5O" functions introduced in HDF5 1.8.0. Not even
# built with API compatibility level below 1.8.
@@ -26,6 +25,9 @@ from utils cimport emalloc, efree
# Initialization
init_hdf5()
+# Runtime imports
+from _sync import sync, nosync
+
# === Public constants ========================================================
TYPE_GROUP = H5O_TYPE_GROUP
diff --git a/h5py/h5p.pyx b/h5py/h5p.pyx
index baa40ca..f6329a5 100644
--- a/h5py/h5p.pyx
+++ b/h5py/h5p.pyx
@@ -15,7 +15,6 @@ __doc__ = \
"""
include "config.pxi"
-include "sync.pxi"
# Compile-time imports
from h5 cimport init_hdf5
@@ -29,6 +28,8 @@ from h5t cimport TypeID, py_create
init_hdf5()
import_array()
+# Runtime imports
+from _sync import sync, nosync
# === C API ===================================================================
diff --git a/h5py/h5r.pyx b/h5py/h5r.pyx
index d5a8256..e2c33fe 100644
--- a/h5py/h5r.pyx
+++ b/h5py/h5r.pyx
@@ -15,7 +15,6 @@ __doc__ = \
"""
include "config.pxi"
-include "sync.pxi"
# Pyrex compile-time imports
from h5 cimport init_hdf5, ObjectID
@@ -25,6 +24,8 @@ from h5s cimport SpaceID
# Initialization
init_hdf5()
+# Runtime imports
+from _sync import sync, nosync
# === Public constants and data structures ====================================
diff --git a/h5py/h5s.pyx b/h5py/h5s.pyx
index 6cc7efe..7649bb0 100644
--- a/h5py/h5s.pyx
+++ b/h5py/h5s.pyx
@@ -15,7 +15,6 @@ __doc__ = \
"""
include "config.pxi"
-include "sync.pxi"
# Pyrex compile-time imports
from h5 cimport init_hdf5
@@ -27,6 +26,9 @@ from python_string cimport PyString_FromStringAndSize
# Initialization
init_hdf5()
+# Runtime imports
+from _sync import sync, nosync
+
cdef object lockid(hid_t id_):
cdef SpaceID space
space = SpaceID(id_)
diff --git a/h5py/h5t.pyx b/h5py/h5t.pyx
index 929ccb4..18c100a 100644
--- a/h5py/h5t.pyx
+++ b/h5py/h5t.pyx
@@ -58,7 +58,6 @@ __doc__ = \
"""
include "config.pxi"
-include "sync.pxi"
# Pyrex compile-time imports
from h5 cimport init_hdf5, H5PYConfig, get_config, PHIL, get_phil
@@ -75,6 +74,7 @@ init_hdf5()
# Runtime imports
import sys
import h5
+from _sync import sync, nosync
cdef H5PYConfig cfg = get_config()
cdef PHIL phil = get_phil()
diff --git a/h5py/h5z.pyx b/h5py/h5z.pyx
index f4c288f..c5bc3b2 100644
--- a/h5py/h5z.pyx
+++ b/h5py/h5z.pyx
@@ -16,7 +16,6 @@ __doc__ = \
"""
include "config.pxi"
-include "sync.pxi"
# Pyrex compile-time imports
from h5 cimport init_hdf5
@@ -24,6 +23,9 @@ from h5 cimport init_hdf5
# Initialization
init_hdf5()
+# Runtime imports
+from _sync import sync, nosync
+
# === Public constants and data structures ====================================
FILTER_LZF = H5PY_FILTER_LZF
diff --git a/h5py/sync.pxi b/h5py/sync.pxi
deleted file mode 100644
index 1584d75..0000000
--- a/h5py/sync.pxi
+++ /dev/null
@@ -1,46 +0,0 @@
-#+
-#
-# This file is part of h5py, a low-level Python interface to the HDF5 library.
-#
-# Copyright (C) 2008 Andrew Collette
-# http://h5py.alfven.org
-# License: BSD (See LICENSE.txt for full license)
-#
-# $Date$
-#
-#-
-
-# Header file which defines decorators for thread safety and debug logging.
-# Intended to be included in the beginning of module .pyx files.
-
-# sync: Acquire PHIL for this function, and log function entry in
-# debug mode.
-# nosync: Don't acquire PHIL, but log function entry in debug mode.
-
-
-include "config.pxi" # For H5PY_* defines
-
-
-IF H5PY_DEBUG:
- import logging
- from _extras import h5sync_dummy
- nosync = h5sync_dummy(logging.getLogger('h5py.functions'))
-
- IF H5PY_THREADS:
- from _extras import h5sync
- sync = h5sync(logging.getLogger('h5py.functions'))
- ELSE:
- sync = nosync
-
-ELSE:
- cdef inline object nosync(object func):
- return func
-
- IF H5PY_THREADS:
- from _extras import h5sync
- sync = h5sync()
- ELSE:
- cdef inline object sync(object func):
- return func
-
-
diff --git a/h5py/utils.pyx b/h5py/utils.pyx
index 112b4e3..bead290 100644
--- a/h5py/utils.pyx
+++ b/h5py/utils.pyx
@@ -11,7 +11,6 @@
#-
include "config.pxi"
-include "sync.pxi"
# Compile-time imports
from h5 cimport init_hdf5
@@ -29,6 +28,8 @@ from numpy cimport ndarray, import_array, \
init_hdf5()
import_array()
+# Runtime imports
+from _sync import sync, nosync
# === Exception-aware memory allocation =======================================
diff --git a/setup.py b/setup.py
index aaa50ce..47cb7df 100644
--- a/setup.py
+++ b/setup.py
@@ -182,10 +182,9 @@ class cybuild(build):
('api=', 'a', 'Set API levels (--api=16 or --api=18)'),
('cython','y','Run Cython'),
('cython-only','Y', 'Run Cython and stop'),
- ('diag', 'd','Enable library debug logging'),
- ('no-threads', 't', 'Build without thread support')]
+ ('diag', 'd','Enable library debug logging')]
- boolean_options = build.boolean_options + ['cython', 'cython-only', 'no-threads','diag']
+ boolean_options = build.boolean_options + ['cython', 'cython-only', 'diag']
def initialize_options(self):
build.initialize_options(self)
@@ -198,16 +197,12 @@ class cybuild(build):
self.cython = False
self.cython_only = False
self.diag = False
- self.no_threads = False
def finalize_options(self):
build.finalize_options(self)
- if self.no_threads:
- warn("Option --no-threads will disappear soon")
-
if self.hdf5 is not None:
self.hdf5 = op.abspath(self.hdf5)
if not op.exists(self.hdf5):
@@ -297,12 +292,10 @@ DEF H5PY_16API = %(API_16)d # 1.6.X API available (always true, for now)
DEF H5PY_18API = %(API_18)d # 1.8.X API available
DEF H5PY_DEBUG = %(DEBUG)d # Logging-level number, or 0 to disable
-
-DEF H5PY_THREADS = %(THREADS)d # Enable thread-safety and non-blocking reads
"""
return pxi_str % {"VERSION": VERSION, "API_MAX": self.api,
"API_16": True, "API_18": self.api == 18,
- "DEBUG": 10 if self.diag else 0, "THREADS": not self.no_threads}
+ "DEBUG": 10 if self.diag else 0}
def read_pxi(self):
""" Returns the current config.pxi file, or an empty string. """
@@ -336,7 +329,6 @@ DEF H5PY_THREADS = %(THREADS)d # Enable thread-safety and non-blocking reads
print "Running Cython (%s)..." % Version.version
print " API level: %d" % self.api
- print " Thread-aware: %s" % ('yes' if not self.no_threads else 'no')
print " Diagnostic mode: %s" % ('yes' if self.diag else 'no')
print " HDF5: %s" % ('default' if self.hdf5 is None else self.hdf5)
--
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