User avatar
Ace Rimmer
Posts: 104
Joined: Wed May 27, 2015 1:51 am
Location: Wit's End

Picamera & Interrupts

Mon Aug 28, 2017 5:37 am

Hi, I hope someone can help me solve my problem. I am writing a small script which "interrupts" a video recording and then starts recording to a new file. The script works when I run it in the Python shell, however when I try to run it from the command line it fails in one of two ways -

if run using Python2 when the interrupt occurs it terminates and returns an error -

Code: Select all

sys.excepthook is missing

lost sysstderr 
if run using Python3 when the interrupt occurs the script terminates and doesn't record the second file.

Code: Select all

 #!/usr/bin/env python3.4.2
print ('   INITIALISING >>>>>>')
import io
import picamera
import datetime as dt
from time import *

import RPi.GPIO as GPIO

GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)

def my_callback(channel):
     print ('apogee detected')'  %H:%M:%S ')

def apogeedetected():
     with picamera.PiCamera() as camera:
             start =
             strrt = time()
             while ( - start).seconds < 10:#   
                  camera.annotate_text ='  PART B  %d-%m-%y    %H:%M:%S       Recording          ')+ str( round(time()-strrt,0))+(' SECONDS      ' )

print ( 'initialising complete......')

GPIO.add_event_detect(17, GPIO.FALLING, callback=my_callback, bouncetime=300)
## PART A ##

with picamera.PiCamera() as camera:
    start =
    strrt = time()
    camera.annotate_background =picamera.Color('green')
    while GPIO.input(17):
         camera.annotate_text ='  PART AAA   %d-%m-%y    %H:%M:%S    Recording ')+ str(20- round(time()-strrt,0))+(' SECONDS       ' )

GPIO.cleanup()           # clean up GPIO on normal exit

Why does it work from the Python shell but not the command line ? :? Any suggestions?
There must be an easier way!!!!!
I hope there is.....I haven't found it yet.

Return to “Camera board”