title: Python script can't be terminated through Ctrl+C or Ctrl+Break
body: <p>I have this simple python script called <code>myMain.py</code> to execute another python program automatically with incremental number, and I'm running it on CentOS 7:</p>
  
  <pre><code>#!/usr/bin/python
  
  import os
  import sys
  import time
  
  def main():
      step_indicator = ""
      arrow = "&gt;"
      step = 2
      try:
          for i in range(0,360, step):
              step_percentage = float(i)/360.0 * 100
              if i % 10 == 0:
                  step_indicator += "="
              os.system("python myParsePDB.py -i BP1.pdb -c 1 -s %s" % step)
              print("step_percentage%s%s%.2f" % (step_indicator,arrow,step_percentage)+"%")
      except KeyboardInterrupt:
          print("Stop me!")
          sys.exit(0)
  
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>For now I only know this script is single thread safe, but I can't terminate it with <code>Ctrl+C</code> keyboard interruption.</p>
  
  <p>I have read some relative questions: such as <a href="https://stackoverflow.com/a/11816038/3781320">Cannot kill Python script with Ctrl-C</a> and <a href="https://stackoverflow.com/q/1364173/3781320">Stopping python using ctrl+c</a> I realized that <code>Ctrl+Z</code> does not kill the process, it only pauses the process and keep the process in background. <code>Ctrl+Break</code> does work for my case either, I think it only terminates my main thread but keeps the child process. </p>
  
  <p>I also noticed that calling <code>os.system()</code> will spawn a child process from the current executing process. At the same time, I also have <code>os</code> file I/O functions and <code>os.system("rm -rf legacy/*")</code> will be invoked in <code>myParsePDB.py</code> which means this <code>myParsePDB.py</code> child process will spawn child process as well. Then, if I want to catch <code>Ctrl+C</code> in <code>myMain.py</code>, should I daemon only <code>myMain.py</code> or should I daemon each process when they spawn?</p>