title: Manually closing subprocess.PIPE
body: <p>I am using </p>
  
  <pre><code>std = subprocess.PIPE 
  </code></pre>
  
  <p>and checking a particular term in every line of the output.If I get 'done', I manually kill the subprocess by os.kill :</p>
  
  <pre><code>p = subprocess.Popen(['vprobe' ,'/vprobe/myhello.emt'], shell = False, stdout=subprocess.PIPE, preexec_fn=os.setsid)
  while True:
     line = p.stdout.readline()
     logfile.write(line)
     if re.search("done", line):
        break
     print "waiting"
  os.kill(p.pid, signal.SIGINT)
  </code></pre>
  
  <p>The process does get killed (i checked using the 'ps' command in unix) but at the end I get an error that:</p>
  
  <pre><code>close failed in file object destructor:
  Error in sys.excepthook:
  Original exception was:
  </code></pre>
  
  <p>which I think is most probably because I have killed the process without actually closing the PIPE. Any suggestions how I can manually do it?</p>