[Patches] [ python-Patches-428326 ] Timer class for threading
noreply@sourceforge.net
noreply@sourceforge.net
Wed, 05 Sep 2001 06:46:03 -0700
Patches item #428326, was opened at 2001-05-29 08:20
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=428326&group_id=5470
Category: library
Group: None
>Status: Closed
>Resolution: Accepted
Priority: 5
Submitted By: Itamar Shtull-Trauring (itamar)
Assigned to: Nobody/Anonymous (nobody)
Summary: Timer class for threading
Initial Comment:
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.
----------------------------------------------------------------------
>Comment By: Martin v. Löwis (loewis)
Date: 2001-09-05 06:46
Message:
Logged In: YES
user_id=21627
Thanks for the patch; it is committed as threading.py 1.18,
libthreading.tex 1.11, NEWS 1.230.
----------------------------------------------------------------------
Comment By: Itamar Shtull-Trauring (itamar)
Date: 2001-09-04 07:49
Message:
Logged In: YES
user_id=32065
I've attached a patch to the documentation. I don't know
LaTex so there may be some errors (although the HTML output
seems OK).
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2001-08-10 06:51
Message:
Logged In: YES
user_id=6380
OK. Let's do a one-short timer only.
----------------------------------------------------------------------
Comment By: Martin v. Löwis (loewis)
Date: 2001-08-10 01:21
Message:
Logged In: YES
user_id=21627
A quick poll among colleagues shows that shoot-once timers
are far more common than repeated intervall timers. You also
can quite easily implement the intervall timer on top of a
shoot-once timer, by restarting it in the timeout handler
(although care is needed if you need exact intervalls:
between last scheduled time-out and the handler invocation,
time may pass, so the restart may need to be smaller than
the intervall).
In short, I think the API as you provide it is excellent; if
people find it useful and require more, they will provide
patches.
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2001-08-09 14:45
Message:
Logged In: YES
user_id=6380
Good!
I don't think there's a standard definition of timers --
I've seen both. A more general timer that can go off N
times, defaulting to once, sounds like a nice API.
Hm, I can actually only think of two usage scenarios: either
you want it to go off once, or you want it to repeat until
you cancel it. Think about it.
There's also the msg from Aahz in the python-dev list where
he claims he doesn't like something about this without
saying what. I hope he clarifies that in this SF tracker
item.
----------------------------------------------------------------------
Comment By: Itamar Shtull-Trauring (itamar)
Date: 2001-08-09 14:23
Message:
Logged In: YES
user_id=32065
1) license can be python's and copyright PSF's
2) I will write docs and tests
3) not sure when, maybe this weekend
One question - timers actually seem to be a task that
happens repeatedly every X seconds (e.g. in wxWindows).
Should I add that functionality (do a task every X seconds,
N times, N is either >= 1 or infinite) or just rename the class?
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2001-08-08 13:53
Message:
Logged In: YES
user_id=6380
I like it too.
But I don't want itamar's license anywhere in the
distribution -- too wordy.
I agree that the PSF should clear up the licensing
situation; we're working
on that but it's slow going (nobody likes this work :-( ).
----------------------------------------------------------------------
Comment By: Martin v. Löwis (loewis)
Date: 2001-08-08 13:32
Message:
Logged In: YES
user_id=21627
I'm in favour of approving this patch, as an extension to
the threading module. Are you willing to draft a patch to
the documentation (libthreading.tex) as well?
Ideally, there would also be a set of regression tests in
a test_threading file; it would be acceptable if this only
tests your feature for the moment.
----------------------------------------------------------------------
Comment By: Itamar Shtull-Trauring (itamar)
Date: 2001-05-30 09:40
Message:
Logged In: YES
user_id=32065
There was a licensing discussion on python-dev which no one
bothered to CC me on :). Yes, this can be relicensed under
the PSF license.
I suggest someone write up some sort of guidelines for
submitted patches and improvement explain the whole
licensing and copyright issues.
----------------------------------------------------------------------
Comment By: Itamar Shtull-Trauring (itamar)
Date: 2001-05-30 02:16
Message:
Logged In: YES
user_id=32065
OK, I'm un-withdrawing this patch. Just had to get things
straight with our lawyer. The patch is released under the
following license (the X11 license with 4 extra paragraphs
of disclaimers :):
http://www.zoteca.com/opensource/LICENSE.txt
----------------------------------------------------------------------
Comment By: Itamar Shtull-Trauring (itamar)
Date: 2001-05-29 09:45
Message:
Logged In: YES
user_id=32065
I'm withdrawing this patch for a short period of time for
non-technical reasons, hopefully I can put it back soon.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=428326&group_id=5470