I have two Python programs that use PiCamera. Program A takes 45 pictures at one minute intervals. Program B takes 5 pictures at one minute intervals. After Program A runs (45 pictures), I get an "out of resources" error if I try to run either program. Program B (5 pictures) can be run multiple times and without any problems and does not affect running of program A. I am running these programs using Crontab, but once Program A runs, everything stops working. I cannot find any command that will reset the Pi camera. The only thing that allows the programs to run again is to reboot. I have added a reboot command to Crontab and I think this will work, but it seems like a klugey solution. Any suggestions would be greatly appreciated. Here is a link to the code: https://gist.github.com/normva/818f27409bd07df04de2b7a5c232d70c
Raspberry Pi 3 Model B v1.2. I have done all the o/s updates/upgrades. GPU was 128, I just updated to 256 (max). The O/S is Buster version 10.
I added: camera.stop_preview in the picture loop of both programs and I no longer get a preview picture. I think that the preview picture was hanging and keeping the camera open. I have run the test program (B) a couple of times with 40 pictures at 1 minute intervals without any problem. Program A will run tomorrow morning at 25 minutes before sunrise. I will then know if the problem has been fixed. I will update the post in the morning when I know the result of the fix.
The problem is not fixed. Got this error when I tried to run test program this morning:
======= RESTART: /home/pi/shared/python_files/cameratesttimestamp02.py ======= Traceback (most recent call last): File "/home/pi/shared/python_files/cameratesttimestamp02.py", line 6, in camera = PiCamera() File "/usr/lib/python3/dist-packages/picamera/camera.py", line 433, in init self._init_preview() File "/usr/lib/python3/dist-packages/picamera/camera.py", line 513, in _init_preview self, self._camera.outputs[self.CAMERA_PREVIEW_PORT]) File "/usr/lib/python3/dist-packages/picamera/renderers.py", line 558, in init self.renderer.inputs[0].connect(source).enable() File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 2212, in enable prefix="Failed to enable connection") File "/usr/lib/python3/dist-packages/picamera/exc.py", line 184, in mmal_check raise PiCameraMMALError(status, prefix) picamera.exc.PiCameraMMALError: Failed to enable connection: Out of resources
The "while" loop was not terminating after one loop. Therefore the camera was not closing and another program using the camera could not be run. The code has been fixed to assure that the program terminates properly.
Norm