From a7499fa3be10b4e1ce587efa7a1833643d231420 Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Tue, 6 Nov 2018 18:49:44 +0000 Subject: [PATCH] Fixed broken context manager __exit__ --- openflexure_microscope/camera/base.py | 1 + openflexure_microscope/camera/pi.py | 12 ++---------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/openflexure_microscope/camera/base.py b/openflexure_microscope/camera/base.py index 5752db6c..e67572d4 100644 --- a/openflexure_microscope/camera/base.py +++ b/openflexure_microscope/camera/base.py @@ -226,6 +226,7 @@ class StreamObject(object): def close(self): """Both clear the stream, and delete any associated on-disk data""" + log("Closing {}".format(self.id)) self.delete_stream() if not self.keep_on_disk: self.delete_file() diff --git a/openflexure_microscope/camera/pi.py b/openflexure_microscope/camera/pi.py index b28ed76a..a5fa7c6d 100644 --- a/openflexure_microscope/camera/pi.py +++ b/openflexure_microscope/camera/pi.py @@ -100,20 +100,12 @@ class StreamingCamera(BaseCamera): # HANDLE CONTEXT MANAGER AND FILE CLOSING def close(self): + """Close method called by BaseCamera __exit__""" # Close all StreamObjects - #TODO: Figure out why this is so slow. for capture_list in [self.images, self.videos]: for stream_object in capture_list: stream_object.close() - - def __enter__(self): - log("Entering context for {}.\ - Stored files will be cleaned up automatically.".format(self)) - return self - - def __exit__(self, *args): - log("Cleaning up {}".format(self)) - self.close() + self.stop_worker() # RETURNING CAPTURES