python - Put a timer on a function inside while loop -


this question has answer here:

there's lots of questions don't quite yet.
have upload code server run 24/7, , code this:

while true:     variable1 = function1()     variable2 = function2()     variable3 = function3() 

so let's want variable2 = function2() once every hour or so, performance (i don't understand it, think it'll put timer on it)

i can't use time.sleep() on because code has keep going
mentioned server thing because don't know if answers using system timer works it, i'm still learning how it.
forgot i'm using python 2.7

not sure if want, here single loop runs 3 functions 3 different periodicities:

import time  t1 = t2 = t3 = 0  period1 = 1.0 # function1() every second period2 = 3600.0  # function2() every hour period3 = 60.0 # function3() every minute  sleep_seconds = 0.1   # or whatever makes sense  while true:      t = time.time()      if t - t1 >= period1:         variable1 = function1()         t1 = time.time()      if t - t2 >= period2:         variable2 = function2()         t2 = time.time()      if t - t3 >= period3:         variable3 = function3()         t3 = time.time()       time.sleep( sleep_seconds ) 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -