2

using tkinter i have made a GUI in which a video plays continuously in a loop until the ultrasonic sensor detects a person in front of it. when a person is detected it displays a messages"hi..welcome". everything works fine but after running for around 20 minutes the raspberry pi freezes with blank black display.

import random
from tkinter import *
import tkinter as tk
from PIL import ImageTk, Image
import time
from datetime import datetime
from subprocess import call
from time import sleep
import serial
import RPi.GPIO as GPIO
import time
import os
import sys
from subprocess import Popen

movie1 = ("/home/pi/1.mp4")

last_state1 = True

quit_video = True

player = False

GPIO.setmode(GPIO.BCM)

TRIG = 23
ECHO = 24

GPIO.setup(TRIG,GPIO.OUT)
GPIO.setup(ECHO,GPIO.IN)

window1 = tk.Tk()
window1.overrideredirect(1)
window1.geometry("900x1200")
window1.configure(background="black")

def create_main_window():

    def off():
        window.destroy()
        on()

    window = tk.Tk()
    window.overrideredirect(1)
    window.geometry("900x1200")
    window.configure(background="black")

    w1 = Label(window, text="Hi..WELCOME..", bg="black", fg="white", font="Times 110")
    w1.place(relx=.5, rely=.4, anchor="c")

    window.after(2000, off)
    window.mainloop()            



def on():
    player = False
    timeout = time.time() + 50
    while True:       
        GPIO.output(TRIG, False)
        print ("wating for sensor to settle")
        time.sleep(1)

        GPIO.output(TRIG, True)
        time.sleep(0.00001)
        GPIO.output(TRIG, False)

        while GPIO.input(ECHO)==0:
                pulse_start = time.time()

        while GPIO.input(ECHO)==1:
                pulse_end = time.time()

        pulse_duration = pulse_end - pulse_start

        distance = pulse_duration * 17150
        distance = round(distance, 2)

        if distance > 1 and distance < 150:
            print ("Distance:",distance - 0.5, "cm")
            os.system('killall omxplayer.bin')
            create_main_window()
        else:
            if not player:
                os.system('killall omxplayer.bin')
                omxc = Popen(['omxplayer', '-b', movie1])
                player = True                    
            else:
                print("hi")
        if time.time() > timeout:
            on()

window1.after(2000, on)
window1.mainloop()  
0

How about trying to quit omxplayer more cleanly (python3) :

import subprocess,time
myprocess = subprocess.Popen(['omxplayer','-b','/opt/vc/src/hello_pi/hello_video/test.h264'],stdin=subprocess.PIPE)
time.sleep(5)
myprocess.stdin.write('q'.encode('utf-8'))
  • thank you @CoderMike .i will try quiting omxplayer with this. but is the freezing because of this mainly or something else?? – shramik Aug 15 '17 at 8:47
  • I don't know for sure, but it would seem sensible to try and exit omxplayer cleanly rather than killing it - it might leave stuff in memory. – CoderMike Aug 15 '17 at 13:14
  • killing a process is not inherently unsafe. The problem with killall is that you don't know which process (and how many of them) you really kill. In rare cases, a process ID might be reused on a system with a heavy load, and then killall will kill a completely unrelated process. – Dmitry Grigoryev Sep 12 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.