[Patches] [ python-Patches-1676820 ] Add a PeriodicTimer to threading
SourceForge.net
noreply at sourceforge.net
Fri Mar 9 08:15:32 CET 2007
Patches item #1676820, was opened at 2007-03-08 22:28
Message generated for change (Comment added) made by loewis
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1676820&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Library (Lib)
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Björn Lindqvist (sonderblade)
Assigned to: Nobody/Anonymous (nobody)
Summary: Add a PeriodicTimer to threading
Initial Comment:
I have often wanted a timer in Python with the same functions as Javas Timer (http://java.sun.com/javase/6/docs/api/java/util/Timer.html). I want it repeating instead of being just a one-shot thing like Pythons Timer class.
Here is a patch that adds such a class to the threading module. You then use it like this:
import threading
def hello():
print "Hi there!"
t = threading.PeriodicTimer(5, hello)
t.start() # "Hi there!" will be printed every five seconds.
The use cases for this class is things like updating canvases, updating simulations and polling stuff. I can provide documentation and unit test patches if this class is deemed worthy.
----------------------------------------------------------------------
>Comment By: Martin v. Löwis (loewis)
Date: 2007-03-09 08:15
Message:
Logged In: YES
user_id=21627
Originator: NO
Looks fine to me. The only issue I see is naming: To stop a periodic
timer, shouldn't the method name be "stop" rather than "cancel"? Also, as
you can hold onto the timer, make sure invoking start/'end' multiple times
in arbitrary order gives meaningful results.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1676820&group_id=5470
More information about the Patches
mailing list