From ca051243a173f83cfaef0e1b46a06a32ca2f562d Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Wed, 27 May 2020 14:24:11 +0100 Subject: [PATCH] Catch timeout errors when closing camera stream --- openflexure_microscope/microscope.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/openflexure_microscope/microscope.py b/openflexure_microscope/microscope.py index aab2fede..c1fe348d 100644 --- a/openflexure_microscope/microscope.py +++ b/openflexure_microscope/microscope.py @@ -71,9 +71,15 @@ class Microscope: """Shut down the microscope hardware.""" logging.info("Closing {}".format(self)) if self.camera: - self.camera.close() + try: + self.camera.close() + except TimeoutError as e: + logging.error(e) if self.stage: - self.stage.close() + try: + self.stage.close() + except TimeoutError as e: + logging.error(e) self.captures.close() logging.info("Closed {}".format(self)) @@ -291,7 +297,7 @@ class Microscope: fmt: str = "jpeg", annotations: dict = None, tags: list = None, - metadata: dict = None + metadata: dict = None, ): if not annotations: annotations = {} @@ -299,7 +305,7 @@ class Microscope: metadata = {} if not tags: tags = [] - + with self.camera.lock: # Create output object output = self.captures.new_image( @@ -312,7 +318,7 @@ class Microscope: use_video_port=use_video_port, resize=resize, bayer=bayer, - fmt=fmt + fmt=fmt, ) # Inject system metadata @@ -324,4 +330,4 @@ class Microscope: # Insert custom tags output.put_tags(tags) - return output \ No newline at end of file + return output