0

I'm using an API to receive data every one second using a structure like this:

from time import sleep
try:
    data = API(options)
except:
    sleep(0.5) 

The whole process is in a bigger loop for repeating that every one second. Sometimes this API returns an error so this structure can handle this issue. But sometimes I think it doesn't return any value for a long time, so this will stop the code, and I need to run the API function again. How can I handle this in my code?

Eghbal
  • 3,892
  • 13
  • 51
  • 112
  • 2
    Is there any indication that no value is returned from the API after a long time? For example, does the API return some sort of Request Timeout exception? – TerryA Mar 11 '19 at 00:26
  • Possible duplicate of [Timeout function if it takes too long to finish](https://stackoverflow.com/questions/2281850/timeout-function-if-it-takes-too-long-to-finish) – Karl Mar 11 '19 at 00:26
  • @TerryA No. It will be stopped for a long time. When I press CTL+C in the IPython, it shows that it's in the exception part and after that, continue the process again. – Eghbal Mar 11 '19 at 00:30
  • 1
    Did you check if this API allows you to set a specific timeout value? – Aurora Wang Mar 11 '19 at 00:59
  • @AuroraWang Yes. I didn't find anything. – Eghbal Mar 11 '19 at 11:35

0 Answers0