title: How to schedule python script to exit at given time
body: <p>I need to schedule a python script which can exit and kill it self at a given time. For scheduling, I am using python <code>schedule</code> and below is the code:</p>
  
  <pre><code>import schedule
  from threading import Thread
  import time
  import sys
  
  
  def exit_data():
      print("Exiting")
      sys.exit()
  
  def exit_data_thread():
      schedule.every().day.at('13:20').do(exit_data)
      while True:
          schedule.run_pending()
          time.sleep(1)
  
  
  def main():
      Thread(target=exit_data_thread).start()
  
      while True:
          time.sleep(1)
  
  main()
  </code></pre>
  
  <p>Function <code>exit_data()</code> runs at given time and it prints <code>Exiting</code> but do not exit. It only prints <code>Exiting</code> and then it keeps running. I have also used  <code>quit</code> instead of <code>sys.exit()</code>. Please help. Thanks</p>