开发者

Repeating function over certain amount of time

开发者 https://www.devze.com 2023-03-10 05:16 出处:网络
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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消