PI Camera Python App - Kernel Panic

For some odd reason my python camera application causes a kernel panic and only runs for a few minutes.

Can any one spot any mistakes?

# Core Python Liberies
 import logging

 import os
 import json

 import time
 import datetime

# Non Core Phyton Liberies
 from picamera import PiCamera
 from picamera import Color
 # sudo apt-get install python3-picamera

# Variable Declaration
 dictionary_config = {}

# Object Declaration
 camera = PiCamera()

# Application Runs From Here
 if __name__ == '__main__':
 try:

 # Change Runtime Directory
      try:
           variable_path =  os.path.dirname(os.path.realpath(__file__))
           os.chdir(variable_path)

      except:
           exit('Runtime Directory Change Failed')

 # Load Application Configeration Dictionary
      try:
           if (os.path.isfile('config.json')):
                try:
                     object_file = open('config.json', 'r')
                     dictionary_config = json.load(object_file)
                     object_file.close()

                except Exception as variable_exception:
                     exit(variable_exception)
           else:
                logging.error('Application Config File Not found')
                exit(1)

      except Exception as variable_exception:
           exit(variable_exception)

 # Logging
      try:
           if(len(dictionary_config['application']['log_level']) <= 0):
                dictionary_config['application']['log_level'] = 'DEBUG'
                dictionary_config['application']['log_file']  = ''

           if (os.path.isfile('debug.console')):
                dictionary_config['application']['log_level'] = 'DEBUG'
                dictionary_config['application']['log_file']  = ''

           logging.basicConfig(filename = dictionary_config['application']['log_file'], level = dictionary_config['application']['log_level'].upper(), format='%(asctime)s - %(levelname)s - %(message)s')

      except Exception as variable_exception:
           logging.error(variable_exception)
           exit(variable_exception)

 # Display
      logging.info('Application')
      logging.info(' ')

      logging.info('Version:')
      logging.info('     %s' %(dictionary_config['application']['version']))
      logging.info(' ')

      logging.info('Log Level:')
      logging.info('     %s' %(dictionary_config['application']['log_level']))
      logging.info(' ')

      logging.info('Log File:')
      logging.info('     %s' %(dictionary_config['application']['log_file']))
      logging.info(' ')

 # Startup Delay
      try:
           time.sleep(int(dictionary_config['application']['application_startup_delay']))

      except Exception as variable_exception:
           logging.error(variable_exception)

 # Watch Directory
      if (os.path.isdir(dictionary_config['images']['export_directory'])):
           logging.info('Export Directory:')
           logging.info('     %s' %(dictionary_config['images']['export_directory']))
      else:
           logging.error('Export Directory Not found')
           exit(1)
      logging.info(' ')

 # Camera Configeration
      logging.info('Camera Configeration:')
      try:
           # Camera
           for variable_dictionary_section in dictionary_config['camera']:
                logging.info('%s:' %(variable_dictionary_section.title() ))

                try:
                     variable_temp = int(dictionary_config['camera'][variable_dictionary_section])
                except Exception as variable_exception:
                     variable_temp = str(dictionary_config['camera'][variable_dictionary_section])

                try:
                     setattr(camera, variable_dictionary_section, variable_temp)
                     logging.info('     %s' %(str(getattr(camera, variable_dictionary_section))))
                except Exception as variable_exception:
                     logging.error(variable_exception)

           # Annotate
           camera.annotate_text = dictionary_config['camera_annotate']['annotate_text']

           camera.annotate_text_size  = int(dictionary_config['camera_annotate']['annotate_text_size'])
           camera.annotate_foreground = Color(dictionary_config['camera_annotate']['annotate_foreground'])
           camera.annotate_background = Color(dictionary_config['camera_annotate']['annotate_background'])

      except Exception as variable_exception:
           logging.error(variable_exception)
           exit(variable_exception)
      logging.info(' ')
        
 # Display
      logging.info('Camera Warm Up 0.5s')
      logging.info(' ')

      # Delay For Camera warm Up
      time.sleep(0.5)

 # Application Loops From Here
      while True:
           try:
                if (os.path.isfile('snap.action')):
                     logging.info(' ')
                     logging.info('----- ----- -----')

                     # Analytics
                     variable_date_time_start = time.perf_counter_ns()

                     variable_temp = dictionary_config['camera_annotate']['annotate_text'] + ' - ' + datetime.datetime.now().strftime('%d-%m-%Y %H-%M-%S')
                          
                     camera.annotate_text = variable_temp
                     camera.capture(dictionary_config['images']['export_directory'] + variable_temp + '.jpg', 'jpeg', True)
                          
                     logging.info('snap')

                     os.remove('snap.action')

                     # Analytics
                     variable_date_time_end = time.perf_counter_ns()

                     logging.info(' ')
                     logging.info('Elapsed Time: %dms' %((variable_date_time_end - variable_date_time_start) / 1000000))

           except Exception as variable_exception:
                logging.error(variable_exception)

 except Exception as variable_exception:
      logging.error(variable_exception)
      exit(variable_exception)

 finally:
 # Release Camera
      try:
           logging.info('Camera Release')
           camera.close()
      except Exception as variable_exception:
           logging.error(variable_exception)

This is the config file:

{
 "application" : {
      "alias"  : "process_cam",

      "version" : "10.5.0.15 - Ghost Revision: 10",

      "log_level" : "DEBUG",
      "log_file"  : "error.log",

      "application_startup_delay"      : "0"
 }, 
 "images" : {
      "export_prefix" : "",
      "export_suffix" : "",
      "export_directory" : "/home/admin/runtime/process_cam/image/"
 },
 "camera" : {
      "hflip" : "1",
      "vflip" : "1",
      "rotation" : "0",
      
      "resolution" : "2592x1944",
      "shutter_speed" : "0",
      
      "sharpness"  : "0",
      "saturation" : "0",
      "contrast"   : "0",
      "brightness" : "50",
      
      "awb_mode"      : "auto",
      "drc_strength"  : "high",
      "exposure_mode" : "auto",
      "image_effect"  : "none"
 },
 "camera_annotate" : {
      "annotate_text" : "snap",
      "annotate_text_size" : "75",
      "annotate_foreground" : "white",
      "annotate_background" : "black"
 }

}

Hello @wernerXVenter Did you ever resolve that?

It’s hard to tell from the code but are you using resize or zoom? I’m having kernel panics after running a few minutes with those set.