Sunday, March 18, 2012

Repeating Timer in Python

While working on Scheduler [1], I've encountered an inconvenience caused by lack of auto-repeat timer in standard Python API.
In this post I will present RepeatTimer class that features:
  • RepeatTimer (as its threading.Timer ancestor) is being executed in a separate thread
  • RepeatTimer executes function on its triggering
  • Interface provides ability to trigger RepeatTimer immediately, and start new countdown
  • Interface provides ability to set new interval that will be applied after upcoming triggering
  • cancel method disengage RepeatTimer and kills its thread
Gist below presents the code:
[1] Scheduler at Github
https://github.com/mushkevych/scheduler

No comments: