General Handling of exceptions and callbacks to end GUI #23
Description
Wasn't quite sure how/where to articulate this, but during my implementation of unit testing and logging I've come across the following issue, which I think I have resolved, its just a bit of a tangle.
It was previously mentioned that there was a non-zero exit code, which was then resolved by adding sys.exit(0).
It appears this was due to the way it was exiting when running out of frames, which was done via Importer.route_frame() raising an error, which was then handled further up with a broad except clause.
I have resolved this by calling the Importer.release() method when there are no remaining frames, as below:
_, image = self.capture.read()
if image is not None:
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
self.proceed(image)
else:
logger.info("No more frames to process, exiting.")
self.release()
Now that there is logging implemented, this approach is going to be cleaner rather than having exceptions bubbling up for things that aren't really exceptions - running out of frames appears to be an intended call to end processing. This method also allows later on a config variable to be passed in to optionally disable this behaviour if needed. @simonarvin Let me know if this approach works for you :)