title: Python 2.7.9 Can not kill subprocess while running script
body: <p>I want to run strandtest.py after running test.py for 5 sec. When I get an input from my remote strandtest.py has to stop so I can go on in the menu again. it's like a screensaver in windows. I can start a subprocess after 5 sec. but when it runs i can't stop it. I tried p.kill() and p.terminate() but they both won't work.</p>
  
  <p><em>os.killpg(os.getpgid(p.pid), signal.SIGTERM)</em> </p>
  
  <p>gives</p>
  
  <p><em>module' object has no attribute 'pid'</em> </p>
  
  <p>Can you help me?</p>
  
  <p>Here's my code</p>
  
  <pre><code>import lirc
  import time
  import os
  import signal
  from subprocess import PIPE,Popen
  import subprocess
  from neopixel import *
  
  Volume = 60
  mute = False
  bool = False
  bool2 = False
  LEDS = 100
  PIN = 18
  BRIGHTNESS = 255
  R     = 255
  G     = 255
  B     = 255
  LED_CHANNEL    = 0
  LED_STRIP      = ws.WS2811_STRIP_GRB
  
  sockid=lirc.init("lifetec", blocking = False)
  strip = Adafruit_NeoPixel(10, PIN, 1050000, 10, False, BRIGHTNESS, LED_CHANNEL, LED_STRIP)
  strip.begin()
  
  def VolumeUp(procent, Bool):
      if Bool == False:
          if procent &lt; 100: 
              Procent = procent + 4
              os.system('amixer -c 1 set Speaker ' + str(Procent) + '%')
              os.system('aplay /share/Wav/Menu/beep-22.wav')
              return Procent
          else:
              os.system('amixer -c 1 set Speaker ' + str(procent) + '%')
              os.system('aplay /share/Wav/Menu/button-3.wav')
      return procent
  
  def VolumeDown(procent, Bool):
      if Bool == False:
          if procent &gt; 0:
              Procent = procent - 4
              os.system('amixer -c 1 set Speaker ' + str(Procent) + '%')
              os.system('aplay /share/Wav/Menu/beep-22.wav')
              return Procent
      return procent
  
  def Mute(Bool):
      print(str(Bool))
      os.system('aplay /share/Wav/Menu/beep-22.wav')
      os.system('amixer sset Speaker toggle')
      os.system('aplay /share/Wav/Menu/beep-23.wav')
      if Bool == False:
          Bool = True
      else:
          Bool = False
      print(str(Bool))
      return Bool
  
  def wheel(pos):
      """Generate rainbow colors across 0-255 positions."""
      if pos &lt; 85:
          return Color(pos * 3, 255 - pos * 3, 0)
      elif pos &lt; 170:
          pos -= 85
          return Color(255 - pos * 3, 0, pos * 3)
      else:
          pos -= 170
          return Color(0, pos * 3, 255 - pos * 3)
  
  def rainbow(strip, wait_ms=20, iterations=1):
          for j in range(256*iterations):
              print("JJJJ = " + str(j))
              for i in range(strip.numPixels()):
          strip.setPixelColor(i, wheel((i+j) &amp; 255))
          strip.show()
          #time.sleep(0.01)
  Gettime = True
  pause = False
  
  while True:
      if Gettime == True:
          timenow = time.time()
          print("timenow Gettime")
          print(timenow)
          Gettime = False
  
      if time.time() - timenow &gt;= 5:
          if pause == False:
              print time.time() - timenow
              print("pause")
              bool = True
              pause = True
      if bool == True:
          p = subprocess.Popen('python strandtest.py', stdout=subprocess.PIPE, shell=True, preexec_fn=os.setsid)
          bool = False
      if bool2 == True:
          gelukt = os.killpg(os.getpgid(p.pid), signal.SIGTERM)
          Gettime = True
          print(gelukt)
          bool2 = False
  
      codeIR = lirc.nextcode()
      if codeIR != []:
          if codeIR[0] == "KEY_VOLUMEUP":
              print codeIR[0]
              print Volume
              Volume = VolumeUp(Volume, mute)
              print Volume
          if codeIR[0] == "KEY_VOLUMEDOWN":
              print codeIR[0]
              print Volume
              Volume = VolumeDown(Volume, mute)
              print Volume
          if codeIR[0] == "KEY_0":
              print codeIR[0]
              print Volume
              mute = Mute(mute)
              print Volume
          if codeIR[0] == "KEY_POWER":
              print codeIR[0]
              os.system("/share/RadVanAdvontuur.py 100 255 255 0")
          if codeIR[0] == "KEY_PAGEUP":
              print codeIR[0]
              bool2 = True
              pause = False
      if codeIR[0] == "KEY_PAGEDOWN":
              print codeIR[0]
              bool = True
              print "script running"
  </code></pre>