title: Best method of continuously collecting data from an API?
body: <p>So I have a python script that is continuously collecting data from APIs and then periodically (e.g. every minute) saves them to an excel file. For this I have a VPS running the code 24/7. As I need data from multiple sources and they need to be updated at different frequencies, my solution was creating a separate function for each type of data, and then calling all of them in separate threads. </p>
  
  <p>As an example here's one of them:</p>
  
  <pre><code>def ExchangeRateCheck(self):
      while True:
          try:
              self.exchangeRate = self.oanda.get_prices(instruments="AUD_USD").get('prices')[0]['ask']
          except:
              try:
                  self.exchangeRate = requests.get('http://free.currencyconverterapi.com/api/v3/convert?q=AUD_USD').json()['results']['AUD_USD']['val']
              except:
                  pass
  
          time.sleep(30)
  
  ratethread = threading.Thread(target=self.ExchangeRateCheck, args=())
  ratethread.daemon = True
  ratethread.start()
  </code></pre>
  
  <p>To account for the times when the API can't be reached, everything is nested in try/except clauses. What I found however is that some threads still end up exiting at some point for some unknown reason.</p>
  
  <p>My questions are:
  For this type of task is using a remote VPS and separate functions in a while True loop the best solution? Is there a better way to collect data 24/7? Could I handle the exceptions better to ensure the code never stops running?</p>
  
  <p>As you can probably tell I'm not a professional developer so any feedback is highly appreciated, feel free to go hard on me I won't get offended.</p>