0

I'm trying to make a camera application with my Raspberry Pi that should launch on RPi startup. The program itself works fine. My problem is I'm getting the error

picamera.exc.PiCameraMMALError: Failed to enable connection: Out of resources

Now I know that this error is due to the RPi using the camera already in another instance. But here lies a problem I'm unable to find an answer to: The aim is to use the RPi headless i.e. without a display or keyboard etc. When I unplug the RPi from a power source, the camera instance seems to stay in some memory or at least it is not closed.

If I'm successful at executing my app properly on startup and unplug the RPi from its power source, the app will not run on the next startup and will instead result in the error above. My best solution so far is to start up the RPi, shut it down manually (reboot won't do it) and unplug + replug the power, after which the old camera instance does not exist anymore.

I cannot create a new camera instance and try to shut all camera instances down that way, because the error above is the result of trying to create the new camera instance.

Is there a way to programmatically "release" all current camera instances without referring directly to them (in Python)? The other alternative is to run a Raspbian bash/shell/etc. script on startup before running the application itself. If this is the only or more feasible option, I'm up to it.

I'm currently using the imutils.video module for interacting with the PiCamera, but if there is some other package that offers the utility I'm looking for, I'm up for the change.

  • No software object can survive a reboot, so releasing "camera instances" will not help since there aren't any. This is likely a hardware issue with the camera not powering up properly during a reboot or after an outrage. Getting a different power supply may help, and using e.g. a relay to unplug/replug the power should help. – Dmitry Grigoryev Sep 12 '19 at 13:16
  • Do you execute sudo systemctl poweroff or similar command before unplug the RasPi from power or do you just pull out the power source? – Ingo Sep 12 '19 at 15:36

Your Answer

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

Browse other questions tagged or ask your own question.