title: Ctrl C won't kill looped subprocess in Python
body: <p>Is there a proper way to create a script that loops through files in a folder and executes a subprocess that can be externally killed with Ctrl C? I have something like the following embedded in a pipeline and cannot Ctrl C it from the command line when the main process is killed. </p>
  
  <p>Example script:</p>
  
  <pre><code>import subprocess
  import os
  import sys
  
  input_directory = sys.argv[1]
  
  for file in os.listdir(os.path.abspath(input_directory)):
      output = file + "_out.out"
      command = ['somescript.py', file, output]
      try:
          subprocess.check_call(command)
      except:
          print "Command Failed"
  </code></pre>
  
  <p>I would then execute program: </p>
  
  <pre><code>Example_script.py /path/to/some/directory/containing/files/
  </code></pre>
  
  <p>While it is looping, if I see the command failed, I want use Ctrl C. However, it fails and continues to run additional subprocesses despite the main script has been destroyer with Ctrl C. Is there a proper way to write something like this that can kill the childs (additional subprocess) with Ctrl C? </p>
  
  <p>Any help, or pointing me in the direction is appreciated greatly. I am currently looking for a good method to do. </p>