I am trying to create a media panel program that displays a picture slideshow. The codes uses pygame to load and display the images.
The Pi will lock up about an hour or so into the runtime and will not respond to any input. The green LED for ACT is solid green during this lock up and blinking during normal use.
I have tried to monitor the memory usage of this program and it remained constant. I have also tried to encapsulate different bits in try except blocks to catch any exceptions with no luck.
Does anyone have any insight into what is causing the lock up?
Current code:
# This program is a media panel program with the following functions:
# digital picture frame (WIP)
import pygame, os, datetime, time, random, settingsPictureFrame, logging
from os.path import isfile, join
logging.basicConfig(filename='mediaPanel.log',level=logging.DEBUG)
pygame.init()
pygame.mouse.set_visible(False)
# could move these to the settings file
width = 1920
height = 1080
size = (width, height)
timeValid = False
processRunning = False
screen = pygame.display.set_mode(size,pygame.FULLSCREEN)
#allows shutdown of media panel
def waitDuration(seconds):
running = True
start_ticks = pygame.time.get_ticks() #starting tick
while (int(seconds) > (pygame.time.get_ticks()-start_ticks)/1000):
time.sleep(1)
if running == False: break
try:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
running = False
pygame.mouse.set_visible(True)
pygame.quit()
except Exception as e:
logging.exception("message")
# load image files into list from directory
listFiles = [f for f in os.listdir(settingsPictureFrame.value['directoryImages']) if isfile(join(settingsPictureFrame.value['directoryImages'],f))]
while(True):
# checks if the current time is within a valid time slot
timeNow = datetime.datetime.now().time().strftime('%H:%M')
dayNow = datetime.datetime.today().weekday()
for i in range(0,len(settingsPictureFrame.timeSlot),3):
if dayNow == int(settingsPictureFrame.timeSlot[i]) and timeNow >= settingsPictureFrame.timeSlot[i+1] and timeNow <= settingsPictureFrame.timeSlot[i+2]:
timeValid = True
break
else:
timeValid = False
if timeValid == True:
if processRunning == False:
processRunning = True
# turn on screen
#os.system('tvservice -p')
#os.system('fbset -depth 8 && fbset -depth 16')
image = pygame.image.load(settingsPictureFrame.value['directoryImages'] + random.choice(listFiles))
screen.blit(image,(0,0))
pygame.display.flip() # display image
else:
#logging
try:
image = pygame.image.load(settingsPictureFrame.value['directoryImages'] + random.choice(listFiles))
screen.blit(image,(0,0))
pygame.display.flip() # display image
except Exception as e:
logging.exception("message")
logging.info('image load failed. terminated program')
pygame.quit()
else:
if processRunning == True:
processRunning = False
# turn off screen
#os.system('tvservice -o')
pygame.quit()
waitDuration(settingsPictureFrame.value['durationImage'])