wakeup
— functions for running code at a specific time
This module provides a general timer that triggers the DL-7450 to carry out a task after a specified amount of time has elapsed. It is possible to create a repeating timer, i.e. one that repeats the task periodically. Timers can also be cancelled. Use cases include:
Retrying an operation after a few seconds. For example, if you make an HTTP request which responds with a
Retry-After
header, you can use a timer to schedule the retry attempt.Set up a polling mechanism to check for some state of affairs every few seconds. For example you may have a temperature sensor and you check the temperature every minute.
You may have some screen content that you want to update every few seconds.
You may wish to send a report to your cloud service provider every night.
It is expected that your application main function will do very little work
except for setting up timers and event handlers. The Timer
support
this programming paradigm.
Warning
If there are no references to a Timer, the Python garbage collector may destroy it at any time. It is the responsibility of the application to make sure that timers are not referenced to keep them active. For example:
from wakeup import wakeup
# bad - timer may be garbage collected
wakeup(update_clock, 0.0, 1.0)
# Better. Timer kept in scope.
my_timer = wakeup(update_clock, 0.0, 1.0)