From 288251838c18013e5d664e6460835744ecbce426 Mon Sep 17 00:00:00 2001 From: su530201 <olivier.kaufmann@umons.ac.be> Date: Wed, 21 Jun 2023 13:46:16 +0200 Subject: [PATCH] Tries to handle BrokenBarrier Exception --- ohmpi/hardware_system.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ohmpi/hardware_system.py b/ohmpi/hardware_system.py index 69967c30..9c3db9d8 100644 --- a/ohmpi/hardware_system.py +++ b/ohmpi/hardware_system.py @@ -10,7 +10,7 @@ from ohmpi.hardware_components.abstract_hardware_components import CtlAbstract from ohmpi.logging_setup import create_stdout_logger from ohmpi.utils import update_dict from ohmpi.config import HARDWARE_CONFIG -from threading import Thread, Event, Barrier +from threading import Thread, Event, Barrier, BrokenBarrierError # plt.switch_backend('agg') # for thread safe operations... @@ -408,9 +408,13 @@ class OhmPiHardware: kwargs.update({'elec_dict': elec_dict, 'state': state}) mux_workers[idx] = Thread(target=self.mux_boards[mux].switch, kwargs=kwargs) mux_workers[idx].start() - self.mux_barrier.wait() - for mux_worker in mux_workers: - mux_worker.join() + try: + self.mux_barrier.wait() + for mux_worker in mux_workers: + mux_worker.join() + except BrokenBarrierError: + self.exec_logger.warning('Switching aborted') + status = False else: self.exec_logger.error( f'Unable to switch {state} electrodes: number of electrodes and number of roles do not match!') -- GitLab