APScheduler
In-process task scheduler for Python with cron, interval and date triggers plus pluggable job stores.
Official Documentation ↗APScheduler 3.10+ / Python 3.9+. Check the official docs for the latest API surface.Installation
pip install apschedulerMethods
No methods match this filter.
Overview
APScheduler schedules Python callables using cron, interval or date triggers, running them in a background thread or asyncio loop. Job stores and executors can be swapped for persistence and concurrency control.
Core Methods
Choose a scheduler, start it, and add jobs with add_job, specifying a trigger and an id. Job stores persist schedules, and executors decide where jobs run.
Usage Notes
Use replace_existing with stable job ids to avoid duplicates on restart, set max_instances to avoid overlap, and persist jobs when the process restarts often.
Common Pitfalls
The memory job store loses jobs on restart. Multiple schedulers sharing a store can duplicate execution. Blocking work in the scheduler thread delays other jobs, so keep jobs short or offload them.
Errors
The official API reference declares the following error types:
SchedulerAlreadyRunningError(异常类(start 时调度器已在运行则抛出)) — official text: “SchedulerAlreadyRunningError – if the scheduler is already running” (source: https://apscheduler.readthedocs.io/en/stable/modules/schedulers/base.html, fetched 2026-11-08T19:27:00+08:00)SchedulerNotRunningError(异常类(shutdown 时调度器尚未启动则抛出)) — official text: “SchedulerNotRunningError – if the scheduler has not been started yet” (source: https://apscheduler.readthedocs.io/en/stable/modules/schedulers/background.html, fetched 2026-11-08T19:27:00+08:00)
API reference evidence
Fetched from official sources on 2026-11-08T19:27:00+08:00 via WebFetch https://apscheduler.readthedocs.io/en/stable/modules/schedulers/base.html;WebFetch https://apscheduler.readthedocs.io/en/stable/modules/schedulers/background.html.
BackgroundScheduler→ signature from https://apscheduler.readthedocs.io/en/stable/modules/schedulers/background.html; official text: “class apscheduler.schedulers.background.BackgroundScheduler(gconfig={}, **options) Bases: BlockingScheduler A scheduler that runs in the background using a separate thread (start() will return immediately).”add_job→ signature from https://apscheduler.readthedocs.io/en/stable/modules/schedulers/base.html; official text: “add_job(func, trigger=None, args=None, kwargs=None, id=None, name=None, misfire_grace_time=undefined, coalesce=undefined, max_instances=undefined, next_run_time=undefined, jobstore=‘default’, executor=‘default’, replace_”
FAQ
- Does the scheduler persist jobs by default?
- No. The default memory store loses jobs on restart. Configure a persistent job store such as SQLAlchemy or a supported backend to keep schedules across restarts.
- How do multiple workers behave?
- Each process runs its own scheduler, so a persisted store shared by several workers can fire a job more than once unless a lock or a single-scheduler design prevents it.
- What happens when a job overruns?
- By default the next run can start before the previous finishes, causing overlap. Set max_instances and misfire_grace_time to control concurrency and late execution.
Report a problem with this API docOpens a pre-filled issue on GitHub.