title: How can i set my program to run until get an error and so that if it gets an error it will try again?
body: <p>i have a piece of code that will constantly act on the database and keep it updated, but there is no network outage etc. For some reason, the program is prone to error. I want the program to run every 240 seconds and repeat the process up to 3 times if it gets an error, and if it gets an error 3 times, I want it to return to its old period, that is, every 240 seconds, can you help with this? I would also be very grateful if you could provide information so that I can make my program run in the background.</p>
  <pre><code>import time
  
  
  class mysql_connections():
    def ___init__(self):
        .
        .
        .
    def table_query(self):
        .
        .
        .
  ...
  if __name__ == &quot;__main__&quot;:
  delay = 10
  sql = mysql_connections()
  while 1:
      try:
          time.sleep(delay)
          sql.table_query()
          delay = 240
      except:
          delay = 10
  </code></pre>
  <p>i tried that but it's not clear so much</p>