Commit c9555308 authored by Wout De Nolf's avatar Wout De Nolf Committed by Matias Guijarro

[writer] capture exceptions during finalization

parent e61f7013
......@@ -228,16 +228,8 @@ class NexusScanWriterBase(base_subscriber.BaseSubscriber):
"""
Executed at the end of the event loop
"""
try:
with self._capture_finalize_exceptions():
self._finalize_hdf5()
except BaseException as e:
self._set_state(self.STATES.FAULT, e)
self.logger.error(
"Not properly finalized due to exception:\n{}".format(
traceback.format_exc()
)
)
finally:
self.log_progress("Finished writing to {}".format(repr(self.filename)))
super()._event_loop_finalize(**kwargs)
......@@ -263,17 +255,21 @@ class NexusScanWriterBase(base_subscriber.BaseSubscriber):
self.logger.info("Fetch last data")
for node in self._nodes:
with self._capture_finalize_exceptions():
self._fetch_data(node, last=True)
# Skip because fix length scans can have variable data points
# self.logger.info(
# "Ensure all dataset have the same number of points"
# )
#
# for subscan in self._enabled_subscans:
# with self._capture_finalize_exceptions():
# self._ensure_same_length(subscan)
self.logger.info("Link external data (VDS or raw)")
for node in self._nodes:
with self._capture_finalize_exceptions():
self._ensure_dataset_existance(node)
self.logger.info("Save detector metadata")
......@@ -285,6 +281,16 @@ class NexusScanWriterBase(base_subscriber.BaseSubscriber):
self._finalize_subscan(subscan)
self._mark_done(subscan)
@contextmanager
def _capture_finalize_exceptions(self):
try:
yield
except BaseException as e:
self._set_state(self.STATES.FAULT, e)
self.logger.error(
"Captured finalization exception:\n{}".format(traceback.format_exc())
)
def get_subscan_info(self, subscan, key, default=None, cache=False):
"""
Get from the subscan's info dictionary.
......@@ -963,9 +969,13 @@ class NexusScanWriterBase(base_subscriber.BaseSubscriber):
:param Subscan subscan:
"""
with self._capture_finalize_exceptions():
self._save_positioners(subscan)
with self._capture_finalize_exceptions():
self._create_plots(subscan)
with self._capture_finalize_exceptions():
self._fetch_subscan_metadata(subscan)
with self._capture_finalize_exceptions():
self._fetch_subscan_notes(subscan)
@property
......
......@@ -156,6 +156,7 @@ class NexusScanWriterConfigurable(scan_writer_base.NexusScanWriterBase):
:param Subscan subscan:
"""
super()._finalize_subscan(subscan)
with self._capture_finalize_exceptions():
self._save_applications(subscan)
def mca_iter(self, subscan):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment