summaryrefslogtreecommitdiff
path: root/doc/source/Tutorials
diff options
context:
space:
mode:
authorPicca Frédéric-Emmanuel <picca@debian.org>2022-11-03 10:02:44 +0100
committerPicca Frédéric-Emmanuel <picca@debian.org>2022-11-03 10:02:44 +0100
commit1c380bfeff1e13a9f7d506460336659502ca052d (patch)
tree48081d47748d4563eeaa76662287eb19638c8591 /doc/source/Tutorials
parent4e774db12d5ebe7a20eded6dd434a289e27999e5 (diff)
New upstream version 1.1.0+dfsg
Diffstat (limited to 'doc/source/Tutorials')
-rw-r--r--doc/source/Tutorials/io.rst28
1 files changed, 28 insertions, 0 deletions
diff --git a/doc/source/Tutorials/io.rst b/doc/source/Tutorials/io.rst
index 41a0dd3..4c54bba 100644
--- a/doc/source/Tutorials/io.rst
+++ b/doc/source/Tutorials/io.rst
@@ -324,6 +324,34 @@ For example to process all top-level groups of an HDF5 file:
Note that the method with the `retry` decorator has to be idempotent
as it can be executed several times for one call.
+An equivalent decorator exists for context managers
+
+.. code-block:: python
+
+ import silx.io.h5py_utils
+
+ @silx.io.h5py_utils.retry_contextmanager()
+ def measurement_context(filename, name):
+ """The method will be entered again if
+ any HDF5 IO fails.
+ """
+ with silx.io.h5py_utils.File(filename) as h5file:
+ yield h5file[name]["measurement"]
+
+Generator functions need to have a `start_index` parameter
+
+.. code-block:: python
+
+ import silx.io.h5py_utils
+
+ @silx.io.h5py_utils.retry()
+ def iter_measurement(filename, names, start_index=0):
+ """The method will be iterated again if any HDF5
+ IO fails, possibly with a different start index.
+ """
+ with silx.io.h5py_utils.File(filename) as h5file:
+ for name in names[start_index:]:
+ yield h5file[name]["measurement"]
Additional resources
--------------------