paveliche
Posts: 2
Joined: Sat May 16, 2015 10:21 pm

Kill Pygame process by another script

Sat May 16, 2015 10:26 pm

Hi all
I'm trying to make a script which start / stop another script with button. Second script ia pygame screen with graphics.

The problem: after killing process screen of my second process freezing.

This is my script with button:

Code: Select all

import RPi.GPIO as GPIO
import time
import subprocess, os
import signal

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO_switch = 18  # pin 18
GPIO.setup(GPIO_switch,GPIO.IN)

print "  Press Ctrl & C to Quit"

try:

   run = 0
   while True :
      if GPIO.input(GPIO_switch)==0 and run == 0:
         print "  Started"
         rpistr = "sudo python dht-display-v.0.2.py"
         p=subprocess.Popen(rpistr, stdout=subprocess.PIPE, shell=True, preexec_fn=os.se$
         print "pid : " + str(p.pid)
         run = 1
         while GPIO.input(GPIO_switch)==0:
             time.sleep(0.1)
      if GPIO.input(GPIO_switch)==0 and run == 1:
         print "  Stopped " + str(p.pid) + " : " + str(signal.SIGTERM)
         run = 0
         os.killpg(p.pid, signal.SIGTERM)
         while GPIO.input(GPIO_switch)==0:
             time.sleep(0.1)


except KeyboardInterrupt:
  print "  Quit"
  GPIO.cleanup()

Return to “Python”