Skip to content

Commit

Permalink
silx.io.h5py_utils.File: avoid emitting several time warning if incoh…
Browse files Browse the repository at this point in the history
…erent hdf5 / h5py locking argument

close #4072
  • Loading branch information
payno committed Feb 27, 2025
1 parent 362f2db commit dd7a811
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/silx/io/h5py_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,33 @@

LATEST_LIBVER_IS_V108 = HDF5_HEX_VERSION < calc_hexversion(1, 10, 0)

LOCKING_ARG_CHANGED_H5PY_VS_HDF5_WARMED = False


def only_once(func):
"""
simple decorator to make sure the warning is call at most one time.
"""

def wrapper(*args, **kwargs):
global LOCKING_ARG_CHANGED_H5PY_VS_HDF5_WARMED
if not LOCKING_ARG_CHANGED_H5PY_VS_HDF5_WARMED:
LOCKING_ARG_CHANGED_H5PY_VS_HDF5_WARMED = True
return func(*args, **kwargs)

return wrapper


@only_once
def warm_incoherent_locking_argument():
"""warm the user that file locking behavior has changed in recent versions of libhdf5"""
_logger.critical(
"The version of libhdf5 ({}) used by h5py ({}) is not supported: "
"Do not expect file locking to work.".format(
h5py.version.hdf5_version, h5py.version.version
)
)


def _libver_low_bound_is_v108(libver) -> bool:
if libver is None:
Expand Down Expand Up @@ -373,12 +400,7 @@ def __init__(
"""
# File locking behavior has changed in recent versions of libhdf5
if HDF5_HAS_LOCKING_ARGUMENT != H5PY_HAS_LOCKING_ARGUMENT:
_logger.critical(
"The version of libhdf5 ({}) used by h5py ({}) is not supported: "
"Do not expect file locking to work.".format(
h5py.version.hdf5_version, h5py.version.version
)
)
warm_incoherent_locking_argument()

if mode is None:
mode = "r"
Expand Down

0 comments on commit dd7a811

Please sign in to comment.