title: Inconsistent behavior when attempting to terminate python subprocess running on a thread
body: <p>I am running into problems when I attempt to terminate a run a long running process running on a separate thread.  </p>
  
  <p>The below is the program. WorkOne creates a subprocess and runs a long running process "adb logcat" that generates log lines. I start WorkOne in main(), wait for 5 sec and attempt to stop it. Multiple runs gives multiple outputs</p>
  
  <pre><code>import threading
  import time
  import subprocess
  import sys
  
  class WorkOne(threading.Thread):
  
      def __init__(self):
          threading.Thread.__init__(self)
          self.event = threading.Event()  
          self.process = subprocess.Popen(['adb','logcat'], stdout=subprocess.PIPE, stderr=sys.stdout.fileno())      
  
      def run(self):   
          for line in iter(self.process.stdout.readline,''):            
              #print line
              if self.event.is_set():
                  self.process.terminate()
                  self.process.kill()
                  break;
          print 'exited For'
  
      def stop(self):
          self.event.set()
  
  def main():
  
      print 'starting worker1'
      worker1 = WorkOne()
      worker1.start()
      print 'number of threads: ' + str(threading.active_count())
      time.sleep(5)
      worker1.stop()
      worker1.join(5)
      print 'number of threads: ' + str(threading.active_count())
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>Sometimes I get [A]:</p>
  
  <pre><code>starting worker1
  number of threads: 2
  number of threads: 2
  exited For
  </code></pre>
  
  <p>Sometimes I get [B]:</p>
  
  <pre><code>starting worker1
  number of threads: 2
  number of threads: 1
  exited For
  </code></pre>
  
  <p>Sometimes I get [C]:</p>
  
  <pre><code>starting worker1
  number of threads: 2
  number of threads: 2
  </code></pre>
  
  <p>I think I should expect to get [B] all the time. What is going wrong here?</p>