Hi All,
I need to call a function for evry 10 secs
how can i achieve this in python

Generally, you would store the next time you want to execute, i.e. now+10 seconds,
using a loop,
call the function,
upon the return get the time and calculate the difference between it and the next time and sleep that amount of time,
update the next time, (+10 seconds), and loop again.

Also, Python has a schedule module, as do most operating systems. On Linux you can use cron to execute the program every 10 seconds, if you want to continue forever.

commented: Good advice and not too much. +13

What do you mean by the seconds do you mean this:

10 secs

Like Woooee suggested, cron is usually the best way to schedule something like this reliably. python does have a 'sleep()' function to make this easy though!


import time
while True:
    print "x"

I hope this helps!

You can always use the threading module for scheduling such functions trivially. I.e.

def worker(self, name): 
# check if we need to exit
    while not self._exitflag:

        if self._need_to_do_job:
            # perform jobs


Though when you .join() the function, you will need to wait for the time specified in your self._nap_time variable.