Raspberry Pi在运行时冻结,ACT灯亮绿色

时间:2016-06-20 00:22:40

标签: python python-3.x raspberry-pi pygame

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

Pi将大约一个小时锁定到运行时,并且不会响应任何输入。在此锁定过程中,ACT的绿色LED指示灯呈绿色稳定亮起,并在正常使用过程中闪烁。

我试图监控这个程序的内存使用情况并保持不变。我还尝试在try中封装不同的位,除了块以捕获任何异常而没有运气。

有没有人对导致锁定的原因有任何了解?

当前代码:

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

0 个答案:

没有答案