title: how to automatically re-operate python script file if the process was over or die?
body: <p>I'm really novice about Python, so I don't know exactly how to construct the logic.</p>
  
  <p>This is my code:</p>
  
  <p><strong>a.py</strong></p>
  
  <pre><code>import time
  
  def main()
      while i &lt; 10:
      i = i + 1
      print(i)
      time.sleep(1)
  
  if __name__== '__main__':
      main()
  </code></pre>
  
  <p>This will print 1, 2, 3, 4 ...... 11 sequentially. However, if the code would be terminated in the middle of executing, like print 1, 2, 3, 4 and then crash, how can I make the program start again?</p>
  
  <p>I thought of a way to do it myself by importing the program as a module and checking whether it has crashed. A bit like the following pseudo-code:</p>
  
  <pre><code>import a
  
  while check the a(python file):
      if a is not operating:
          a.main()
      else:
          pass
  </code></pre>
  
  <p>Another question I have is that I want to time the code when I want to stop.</p>