Posts: 1
Joined: Wed Oct 31, 2018 7:39 pm

System lock up on interruption of python camera code

Wed Oct 31, 2018 7:57 pm

I have written this small python code to tell my camera to capture images of the night sky.

Code: Select all


from picamera import PiCamera
from time import sleep
from fractions import Fraction
from shutil import copyfile

import datetime as dt

camera = PiCamera(

camera.rotation = 180
camera.shutter_speed = 6000000
camera.iso = 800
camera.exposure_mode = 'off'

x = 1
while (1):
    string ='%Y-%m-%d_%H_%M_%S')
    fullstring = '/home/pi/nightlapse/images/image_%s.jpg' % string
    print('Starting capture ...')
    print('Captured image %s' %fullstring)
    copyfile(fullstring, '/home/pi/nightlapse/webapp/static/image.jpg')
    x +=1
The images are taken, I see the image file being created in the filesystem about 20 seconds before the program
prints out Captured image .....

My problem is when I want to stop the program.
I use ^C and the program usually interrupts (not always!).
Often the system then becomes unresponsive and cannot be shutdown or connected to remotely.
All I can do at that stage is pull the power (which is abhorrant).

Is this the expected behaviour with the camera and PiCamera?
Have I made a mistake in my code.

I had no lockups before using a cron job to call a bash script that called raspistill every 5 minutes, but
was hoping to get more images as my exposure is 6 seconds.


Return to “Camera board”