I have found the following issues that might relate to this problem:
- Framerates below 1 are not supported (https://github.com/raspberrypi/userland/issues/575)
- Frequent sequential call hang (https://github.com/raspberrypi/userland/issues/564)
I will let the Pi run overnight with a framerate of 1. So far, so good, no crashes after an hour. There is to be a better tomorrow.
I have the following code which takes an image every minute:
def cam_timeout(cam): print("Timeout thread started") time.sleep(20) if not cam.closed: print("Camera timeout reached! Force-closing.") cam.close() else: print("Camera closed, moving on.") print("Waiting before first camera cycle...") time.sleep(5) while True: print("Getting frame now!") cam = PiCamera() # Timeout thread (optional) # ttr = threading.Thread(target=cam_timeout,args=[cam]) # ttr.start() # Main cam logic cam.framerate = globals.FRAMERATE cam.shutter_speed = round(1 / globals.FRAMERATE * 1000000) cam.resolution = globals.RESOLUTION cam.capture('static/img.jpeg') cam.close() print("Camera cycle done!") time.sleep(60)
If I set
globals.FRAMERATE to something lower than
1 OR have the program do captures several times my python process hangs. In the air. No camera connection (LED does not light up), and process hangs (With an optional kernel panic, needing a complete power cycle to the Pi). No response from the timeout thread, no nothing. Even killing the process is a no-go. (You need to kill the shell, although that does not always release the resources owned by the process, ie. a port that I opened...)
If the kernel panic does not happen, I am lucky enough to ssh into the Pi from another session and solve the problem. (Which left me hanging with an unidentified, dangling, defunct and irritating port reservation, from another part of the same program)
tcp 6 0 0.0.0.0:8080 0.0.0.0:* LISTEN -
(Yes, I ran
sudo. EDIT: Same thing here, like with the kernel panic; only a power cycle helped.)
PS.: I own a Raspberry Pi Zero W with a V1.2 camera, running on Python 3.7.3 (HTTP server running on CherryPy 8.9.1).
Edit: Can I power cycle the camera programmatically? Also, raspistill hangs before initialization...