[Python-ideas] Adding threading.RepeatTimer class

Daniel da Silva ddasilva at umd.edu
Thu Jan 27 19:03:18 CET 2011

We have a threading.Timer class which executes after a given delay and then
terminates. I was thinking about a pre-made class that would execute, wait
an interval, and then repeat. It would cut down on the logic people need to
implement themselves, and make simple scripts faster.

Here are some use cases:

# Send a ping message to all connected clients every 120 seconds
from server import ping_all_clients
pinger = threading.RepeatTimer(120, ping_all_clients)

# Check for updates every 3 hours
from mymodule import check_for_updates
update_checker = threading.RepeatTimer(60*60*3, check_for_updates)

I was thinking of the class having an initializer signature as follows:

class threading.RepeatTimer(interval, function, args=[], kwargs={},
     Create a timer that will run function with args and kwargs and repeat
every interval secods. If limit is
     an integer, limits repetitions to that many calls.

         Stop the repeat timer. If in the middle of a call, the call is
allowed to finish.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110127/018c3908/attachment.html>

More information about the Python-ideas mailing list