Schedule is a lightweight, in-process job scheduler for Python that allows you to schedule tasks to run at specific intervals or times. It aims for a human-readable syntax and is designed for simplicity. The current version is 1.2.2, and it maintains a stable, low-cadence release cycle, indicating a mature and well-tested library.
pip install scheduleVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define simple functions as jobs and schedule them to run at set intervals. The `schedule.run_pending()` call within a `while` loop is crucial for the scheduler to check and execute due jobs. The `time.sleep(1)` prevents the loop from consuming too much CPU.
Ensure `schedule.run_pending()` is called regularly, typically in a `while True:` loop with a `time.sleep()` for non-blocking applications, or integrated into an event loop.
To achieve persistence, you would need to re-schedule jobs upon application startup, potentially storing job definitions in a database or configuration file. For long-running background services, consider dedicated job queue systems or OS-level schedulers.
For jobs that might take a significant amount of time, consider running them in separate threads or processes. Libraries like `schedule_threaded` or custom threading solutions can help delegate job execution to avoid blocking the main scheduler loop.
Ensure `schedule.run_pending()` is called repeatedly within an infinite loop, usually combined with `time.sleep()` to prevent excessive CPU usage: `while True: schedule.run_pending(); time.sleep(1)`.
Use `schedule.cancel_job(job_handle)` where `job_handle` is the `Job` object returned when the job was scheduled: `job_handle = schedule.every(...).do(my_func); schedule.cancel_job(job_handle)`.
Pass the function reference and its arguments separately to the `do()` method: `schedule.every(...).do(my_function, 'arg1', kwarg='value')`.
No dependency data recorded yet.