StreamingCamera cleans up StreamObject files automatically on close()
This commit is contained in:
parent
360c836699
commit
fd73732c6a
2 changed files with 23 additions and 2 deletions
|
|
@ -55,6 +55,9 @@ class StreamObject(object):
|
||||||
# Keep on disk after close by default
|
# Keep on disk after close by default
|
||||||
self.keep_on_disk = True
|
self.keep_on_disk = True
|
||||||
|
|
||||||
|
# Log if created by context manager
|
||||||
|
self.context_manager = False
|
||||||
|
|
||||||
# Object lock
|
# Object lock
|
||||||
self.locked = False # Is the StreamObject locked for writing? (Handled by StreamingCamera)
|
self.locked = False # Is the StreamObject locked for writing? (Handled by StreamingCamera)
|
||||||
|
|
||||||
|
|
@ -62,6 +65,7 @@ class StreamObject(object):
|
||||||
log("Entering context for {}.\
|
log("Entering context for {}.\
|
||||||
Stored files will be cleaned up automatically.".format(self.id))
|
Stored files will be cleaned up automatically.".format(self.id))
|
||||||
self.keep_on_disk = False # Flag file to be removed on close.
|
self.keep_on_disk = False # Flag file to be removed on close.
|
||||||
|
self.context_manager = True # Used in metadata
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, *args):
|
def __exit__(self, *args):
|
||||||
|
|
@ -128,6 +132,7 @@ class StreamObject(object):
|
||||||
'locked': self.locked,
|
'locked': self.locked,
|
||||||
'keep_on_disk': self.keep_on_disk,
|
'keep_on_disk': self.keep_on_disk,
|
||||||
'path': self.file,
|
'path': self.file,
|
||||||
|
'context_manager': self.context_manager,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get file path
|
# Get file path
|
||||||
|
|
@ -211,7 +216,6 @@ class StreamObject(object):
|
||||||
os.remove(self.file)
|
os.remove(self.file)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
log("File not found {}".format(self.file))
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def shunt(self):
|
def shunt(self):
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,23 @@ class StreamingCamera(BaseCamera):
|
||||||
"""Run any initialisation code when the frame iterator starts."""
|
"""Run any initialisation code when the frame iterator starts."""
|
||||||
pass
|
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
|
# RETURNING CAPTURES
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue