0

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

6
  • Do you get the same error if you run program A from the command line 'python3 Cameratest.py' let it finish, then run again from the command line? Is there any more detail to the error message? – CoderMike Apr 18 '20 at 22:16
  • Yes, I cannot run program A again. I noticed that if change my test program (B) to take 20 pictures, the preview picture hung on the scene after the program finished. I added: camera.stop_preview in the loop and I no longer get a preview picture. I have not changed the test program to 40 pictures to see if it still works. I have a feeling that the preview may have been hanging with the 45 pictures on Program A. It takes a while to run. I have another 35 minutes to go. – NormVA Apr 18 '20 at 22:43
  • What is the full error message? Which model of pi camera? – CoderMike Apr 19 '20 at 6:49
  • Add a print(‘about to close camera’) and print(‘camera closed’) before and after the camera.close() command just to make sure it is closing. – CoderMike Apr 19 '20 at 17:47
  • I added the comments that you suggested. I was running the program from Crontab, but that does not allow me to see the comments. I cancelled the Crontab and ran the program manually -- using the Crontab statements pasted into the terminal. The program only takes the pictures at sunrise, so we will have to wait until morning. – NormVA Apr 19 '20 at 23:35
0

The program was not terminating after one loop of taking pictures. Therefore the camera was not closed and could not be opened by another program, thus causing an "out of resources" error.

Adjusted the "while" loop to assure that the program ended correctly. The code link in the question has been adjusted to show the updated code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.