Repeating function over certain amount of time
I am writing a program that upload files from my nokia cell phone files to the web server which I am already done writing that. B开发者_运维问答ut, my program only does his job only one time and what I want is that I want to call that function for let's say every 5 mins again and again which I do not know how to do it.
You can use the time
module and the sleep
function.
Just loop forever and sleep
import time
while True:
doUpload()
time.sleep(300) # sleep in seconds
Call your function inside a loop:
In [1]: import time
In [2]: while True:
...: print 'woke up'
...: time.sleep(2)
...:
...:
woke up
woke up
woke up
woke up
woke up
^C
In the above, there is a two-second pause between the 'woke up' messages.
精彩评论