树莓皮在运行时冻结,ACT灯变为绿色

2024-09-29 22:01:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试创建一个显示图片幻灯片的媒体面板程序。代码使用pygame来加载和显示图像。在

Pi会在运行时锁定大约一个小时左右,并且不会对任何输入做出响应。ACT的绿色LED在锁定期间呈绿色,在正常使用期间闪烁。在

我试着监视这个程序的内存使用情况,它保持不变。我还尝试在try-except块中封装不同的位来捕捉任何不幸运的异常。在

有人知道是什么导致了锁死吗?在

当前代码:

# 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'])

Tags: imagefalsetruedatetimeiftimevalueos

热门问题