This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: The function, Threading.Timer.run(), may be Inappropriate
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.1
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, gestapo21th, ggenellina
Priority: normal Keywords:

Created on 2008-12-30 15:44 by gestapo21th, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg78540 - (view) Author: Deli.Zhang (gestapo21th) Date: 2008-12-30 15:44
def run(self):
        self.finished.wait(self.interval)
        if not self.finished.isSet():
            self.function(*self.args, **self.kwargs)
        self.finished.set()

I think the function run() should be modified to like this below:

def run(self):
        while not self.finished.isSet():
            self.finished.wait(self.interval)
            self.function(*self.args, **self.kwargs)

In this case, it can still run on next 'interval', and next's next...
msg78672 - (view) Author: Gabriel Genellina (ggenellina) Date: 2009-01-01 00:54
Note that doing this would change the class semantics.
Timer "[...] represents an action that should be run only after a 
certain amount of time has passed — a timer." and the example clearly 
shows that the action is run *once*. 

Timer is basically an example of how to write custom Thread 
subclasses; if you want a "repetitive action", you may easily write a 
subclass based on the code you posted. Not every useful class must be 
in the standard library...
msg79847 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-01-14 11:07
Indeed, Timer is designed to run the function once.
History
Date User Action Args
2022-04-11 14:56:43adminsetgithub: 49031
2009-01-14 11:07:52amaury.forgeotdarcsetstatus: open -> closed
resolution: works for me
messages: + msg79847
nosy: + amaury.forgeotdarc
2009-01-01 00:54:40ggenellinasetnosy: + ggenellina
messages: + msg78672
2008-12-30 15:44:01gestapo21thcreate