Message36669
| Author |
itamar |
| Recipients |
| Date |
2001年05月29日.15:20:29 |
| SpamBayes Score |
| Marked as misclassified |
| Message-id |
| In-reply-to |
| Content |
The Timer class allows you to schedule an action to
happen at some time in the future, using a thread. For
example:
def f():
print "30 seconds have passed"
t = Timer(30.0, f)
t.start() # after 30 seconds f will be called
try:
# .... other stuff
except SystemExit:
t.cancel() # cancel the timer since we are
shutting down
It allows passing arguments and keyword arguments to
the function that is called. It also allows
*cancelling* the timer. That is, if the timer is still
waiting, we can tell it to stop its operation.
Why should this be in the standard library?
1. Timers are a standard, useful programming idiom.
2. It can be used as an example of how to:
a. create subclasses of threading.Thread
b. make threads that can be "stopped"
If this patch is approved I will then write
documentation. I'm not sure how to go about writing
tests for it. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2007年08月23日 15:05:51 | admin | link | issue428326 messages |
| 2007年08月23日 15:05:51 | admin | create |
|