I want to call a function (actually, it is a web API) every 10 seconds. But the function may take random t second to return. (Assume t is 0.1 to 1.0 sec)
The simplest code we can think of is
while True:
func() # take t sec
time.sleep(10) # sleep 10 sec
but in this case, func
is called every (1+t) seconds.
Are there better ways to do it?
Should we use some multi threading or something like that? Concrete code example will be appreciated. Thank you.