camera.close() should be in a finally block to make sure that we don't

run out of resources because of failed camera initializations
This commit is contained in:
Fabio Manganiello 2019-08-25 16:51:03 +02:00
parent 69a03fa025
commit b9360cf2c5

View file

@ -124,6 +124,9 @@ class CameraPiPlugin(CameraPlugin):
""" """
camera = None
try:
camera = self._get_camera(**opts) camera = self._get_camera(**opts)
image_file = os.path.abspath(os.path.expanduser(image_file)) image_file = os.path.abspath(os.path.expanduser(image_file))
@ -141,9 +144,10 @@ class CameraPiPlugin(CameraPlugin):
if preview: if preview:
camera.stop_preview() camera.stop_preview()
camera.close()
return {'image_file': image_file} return {'image_file': image_file}
finally:
if camera:
camera.close()
@action @action
def capture_sequence(self, n_images, directory, name_format='image_%04d.jpg', preview=False, warmup_time=2, def capture_sequence(self, n_images, directory, name_format='image_%04d.jpg', preview=False, warmup_time=2,
@ -179,6 +183,9 @@ class CameraPiPlugin(CameraPlugin):
""" """
camera = None
try:
camera = self._get_camera(**opts) camera = self._get_camera(**opts)
directory = os.path.abspath(os.path.expanduser(directory)) directory = os.path.abspath(os.path.expanduser(directory))
@ -204,8 +211,9 @@ class CameraPiPlugin(CameraPlugin):
if preview: if preview:
camera.stop_preview() camera.stop_preview()
camera.close()
return {'image_files': images} return {'image_files': images}
finally:
camera.close()
@action @action
def start_time_lapse(self, directory, n_images=None, interval=0, warmup_time=2, def start_time_lapse(self, directory, n_images=None, interval=0, warmup_time=2,