Single-thread interval scheduler
Slowing down. Last release over 2 years ago, little activity since. Fine for existing code; think twice for a new project.
pip install ischeduleREADME as published on PyPI with version 1.2.7.
Schedule periodic tasks in a Python program. Simple syntax, precise timing, no busy waiting. The project was originally made for an industrial automation and IoT application.
Basic example
from ischedule import schedule, run_loop
def task_1():
print("task 1")
def task_2():
print("task 2")
schedule(task_1, interval=1.0)
schedule(task_2, interval=0.2)
run_loop()
Output:
task 2
task 2
task 2
task 2
task 1
task 2
task 2
task 2
task 2
task 2
task 1
Implementational details
Quite importantly, and unlike some other packages, ischedule takes into account the time it takes for the task function to execute. For example, if a task that takes 0.9 seconds to complete is scheduled to run every second, the execution number 1000 will happen exactly 1000 seconds after the start of the program (± a few milliseconds).
There is no busy waiting. Inside the run_loop method, ischedule calculates the time until the next task becomes pending, and idles the CPU until this happens.
What happens during heavy loading
Heavy loading means that there is not enough computer resources to execute all tasks as scheduled. For example, a task that is scheduled to run every second, could take more than a second to complete. Graceful handling of this condition is essential in a well-implemented periodic scheduler.
- If more than one task become pending simultaneously, they will be executed in the order in which they were added to the schedule by
schedule(). - Regardless of the load, no task will be completely starved. All pending tasks will be executed as soon as possible after they become pending.
- There is no build-up of delayed executions. If the execution of a task is delayed so much that the next execution of the same task become pending, an execution will be skipped.