Issue 4781: The function, Threading.Timer.run(), may be Inappropriate (original) (raw)

Issue4781

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:43 admin set github: 49031
2009-01-14 11:07:52 amaury.forgeotdarc set status: open -> closedresolution: works for memessages: + nosy: + amaury.forgeotdarc
2009-01-01 00:54:40 ggenellina set nosy: + ggenellinamessages: +
2008-12-30 15:44:01 gestapo21th create