I have found the following issues that might relate to this problem:

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")
  if not cam.closed:
    print("Camera timeout reached! Force-closing.")
  else: print("Camera closed, moving on.")

print("Waiting before first camera cycle...")
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

  print("Camera cycle done!")


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  *               LISTEN      -

(Yes, I ran netstat with 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...

raspistill hang

  • 1
    It is more likely that your unusual code is causing the problem. Unless I am mistaken this will keep creating threads until the system crashes. – Milliways Oct 13 '19 at 0:00
  • 1
    time.sleep(20) < time.sleep(60) so the child thread will exit before it needs to start again. There is not a single point in time where this program runs on more than 2 threads. – ForceMagic Oct 13 '19 at 0:33

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.