StreamingCamera cleans up StreamObject files automatically on close()

This commit is contained in:
Joel Collins 2018-11-06 18:37:17 +00:00
parent 360c836699
commit fd73732c6a
2 changed files with 23 additions and 2 deletions

View file

@ -96,6 +96,23 @@ class StreamingCamera(BaseCamera):
def initialisation(self):
"""Run any initialisation code when the frame iterator starts."""
pass
# HANDLE CONTEXT MANAGER AND FILE CLOSING
def close(self):
# Close all StreamObjects
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()
# RETURNING CAPTURES