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?