v4.0 系列为预发布版,可能不兼容变更,README 明确警告勿用于生产;多调度器或多 worker 场景需额外配置事件代理(PostgreSQL/Redis/MQTT)
Python 任务调度与任务队列库,支持单机到多节点部署,同步异步皆可
Python 任务调度库,支持 cron、间隔和一次性任务,可把定时作业挂到后台运行,省去自己写调度循环。
核心能力
- 提供同步与异步两种风格,适配线程和 asyncio/Trio 应用
- 支持 Cron、间隔、日历、一次性及组合触发器
- 内置 PostgreSQL、MySQL、SQLite、MongoDB 持久化存储
- 多调度器与 worker 共享数据存储,实现高可用与横向扩展
- 可限制并发任务数、允许延迟启动时长并加入随机抖动
容易踩的坑
- 3.11.3最新正式版2026-06-28 · 2026-06-28 19:39 UTC
- Fixed sub-minute interval jobs stalling for the duration of a DST spring-forward gap when the scheduler was configured with a
ZoneInfotime zone, caused by the wakeup delay being computed from the naive wall-clock difference instead of the actual UTC difference (#1103) - Fixed imported jobs missing their scheduler and job store links (#1119)
- Fixed sub-minute interval jobs stalling for the duration of a DST spring-forward gap when the scheduler was configured with a
- 3.11.22025-12-22 · 2025-12-22 00:39 UTC
查看更新说明
- Fixed an issue where a job using a
CronTriggerscheduled in a repeated time interval during DST transitions could cause the scheduler to get stuck in an infinite loop (#1021; PR by @soulofakuma)
- Fixed an issue where a job using a
- 3.11.12025-10-31 · 2025-10-31 18:55 UTC
查看更新说明
- Fixed
scheduler.shutdown()not raisingSchedulerNotRunning(or raising the wrong exception) for asynchronous schedulers when the scheduler is in fact not running - Fixed
CronTriggersticking on a folded datetime during the fall-back DST transition (#1021 <https://github.com/agronholm/apscheduler/issues/1021>_; PR by @berianjames)`
- Fixed
- 4.0.0a62025-04-27 · 2025-04-27 08:36 UTC
查看更新说明
- BREAKING Refactored
AsyncpgEventBrokerto directly accept a connection string, thus eliminating the need for theAsyncpgEventBroker.from_dsn()class method - BREAKING Added the
extend_acquired_schedule_leases()data store method to prevent other schedulers from acquiring schedules already being processed by a scheduler, if that's taking unexpectedly long for some reason - BREAKING Added the
extend_acquired_job_leases()data store method to prevent jobs from being cleaned up as if they had been abandoned (#864) - BREAKING Changed the
cleanup()data store method to also be responsible for releasing jobs whose leases have expired (so the schedulers responsible for them have probably died) - BREAKING Changed most attributes in
TaskandScheduleclasses to be read-only - BREAKING Refactored the
release_schedules()data store method to take a sequence ofScheduleResultinstances instead of a sequence of schedules, to enable the memory data store to handle schedule updates more efficiently - BREAKING Replaced the data store
lock_expiration_delayparameter with a new scheduler-level parameter,lease_durationwhich is then used to call the various data store methods - BREAKING Added the
job_result_expiration_timefield to theScheduleclass, to allow the job results from scheduled jobs to stay around for some time (#927) - BREAKING Added an index for the
created_atjob field, so acquiring jobs would be faster when there are a lot of them - BREAKING Removed the
job_executorandmax_running_jobsparameters fromadd_schedule()andadd_run_job()(explicitly configure the task usingconfigure_task()or by using the new@taskdecorator - BREAKING Replaced the
default_job_executorscheduler parameter with a more comprehensivetask_defaultsparameter - Added the
@taskdecorator for specifying task configuration parameters bound to a function - BREAKING Changed tasks to only function as job templates as well as buckets to limit maximum concurrent job execution
- BREAKING Changed the
timezoneargument toCronTrigger.from_crontab()into a keyword-only argument - BREAKING Added the
metadatafield to tasks, schedules and jobs - BREAKING Added logic to store
last_fire_timein datastore implementations (PR by @hlobit) - BREAKING Added the
reap_abandoned_jobs()abstract method toDataStorewhich the scheduler calls before processing any jobs in order to immediately mark jobs left in an acquired state when the scheduler crashed - Added the
start_timeandend_timearguments toCronTrigger.from_crontab()(#676) - Added the
psycopgevent broker - Added useful indexes and removed useless ones in
SQLAlchemyDatastoreandMongoDBDataStore - Changed the
lock_expiration_delayparameter of built-in data stores to accept atimedeltaas well asintorfloat - Fixed serialization error with
CronTriggerwhen pausing a schedule (#864) - Fixed
TypeError: object NoneType can't be used in 'await' expressionat teardown ofSQLAlchemyDataStorewhen it was passed a URL that implicitly created a synchronous engine - Fixed serializers raising their own exceptions instead of
SerializationErrorandDeserializationErroras appropriate - Fixed
repr()outputs of schedulers, data stores and event brokers to be much more useful and reasonable - Fixed race condition in
MongoDBDataStorethat allowed multiple schedulers to acquire the same schedules at once - Changed
SQLAlchemyDataStoreto automatically create the explicitly specified schema if it's missing (PR by @zhu0629) - Fixed an issue with
CronTriggerinfinitely looping to get next date when DST
- BREAKING Refactored
- 3.11.02024-11-24 · 2024-11-24 19:42 UTC
查看更新说明
- Dropped support for Python 3.6 and 3.7
- Added support for
ZoneInfotime zones and deprecated support for pytz time zones - Added
CalendarIntervalTrigger, backported from the 4.x series - Added the ability to export and import jobs via
scheduler.export_jobs()andscheduler.import_jobs(), respectively - Removed the dependency on
six - Changed
ProcessPoolExecutorto spawn new subprocesses from scratch instead of forking on all platform - Fixed
AsyncIOSchedulerinadvertently creating a defunct event loop at start, leading to the scheduler not working at all - Fixed
ProcessPoolExecutornot respecting the passed keyword arguments when a broken pool was being replaced
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
.. image:: https://github.com/agronholm/apscheduler/actions/workflows/test.yml/badge.svg :target: https://github.com/agronholm/apscheduler/actions/workflows/test.yml :alt: Build Status .. image:: https://coveralls.io/repos/github/agronholm/apscheduler/badge.svg?branch=master :target: https://coveralls.io/github/agronholm/apscheduler?branch=master :alt: Code Coverage .. image:: https://readthedocs.org/projects/apscheduler/badge/?version=latest :target: https://apscheduler.readthedocs.io/en/master/?badge=latest :alt: Documentation
.. warning:: The v4.0 series is provided as a pre-release and may change in a backwards incompatible fashion without any migration pathway, so do NOT use this release in production!
Advanced Python Scheduler (APScheduler) is a task scheduler and task queue system for Python. It can be used solely as a job queuing system if you have no need for task scheduling. It scales both up and down, and is suitable for both trivial, single-process use cases as well as large deployments spanning multiple nodes. Multiple schedulers and workers can be deployed to use a shared data store to provide both a degree of high availability and horizontal scaling.
APScheduler comes in both synchronous and asynchronous flavors, making it a good fit for both traditional, thread-based applications, and asynchronous (asyncio or Trio_) applications. Documentation and examples are provided for integrating with either WSGI_ or ASGI_ compatible web applications.
Support is provided for persistent storage of schedules and jobs. This means that they can be shared among multiple scheduler/worker instances and will survive process and node restarts.
The built-in persistent data store back-ends are:
- PostgreSQL
- MySQL and derivatives
- SQLite
- MongoDB
The built-in event brokers (needed in scenarios with multiple schedulers and/or workers):
- PostgreSQL
- Redis
- MQTT
The built-in scheduling mechanisms (triggers) are:
- Cron-style scheduling
- Interval-based scheduling (runs tasks on even intervals)
- Calendar-based scheduling (runs tasks on intervals of X years/months/weeks/days, always at the same time of day)
- One-off scheduling (runs a task once, at a specific date/time)
Different scheduling mechanisms can even be combined with so-called combining triggers (see the documentation_ for details).
You can also implement your custom scheduling logic by building your own trigger class. These will be treated no differently than the built-in ones.
Other notable features include:
- You can limit the maximum number of simultaneous jobs for a given task (function)
- You can limit the amount of time a job is allowed to start late
- Jitter (adjustable, random delays added to the run time of each scheduled job)
.. _Trio: https://pypi.org/project/trio/ .. _WSGI: https://wsgi.readthedocs.io/en/latest/what.html .. _ASGI: https://asgi.readthedocs.io/en/latest/index.html .. _documentation: https://apscheduler.readthedocs.io/en/master/
Documentation
Documentation can be found
here <https://apscheduler.readthedocs.io/en/master/?badge=latest>_.
Source
The source can be browsed at Github <https://github.com/agronholm/apscheduler>_.
Reporting bugs
A bug tracker <https://github.com/agronholm/apscheduler/issues>_ is provided by
GitHub.
Getting help
If you have problems or other questions, you can either:
- Ask in the
apscheduler <https://gitter.im/apscheduler/Lobby>_ room on Gitter - Post a question on
GitHub discussions_, or - Post a question on StackOverflow_ and add the
apschedulertag
.. _GitHub discussions: https://github.com/agronholm/apscheduler/discussions/categories/q-a .. _StackOverflow: http://stackoverflow.com/questions/tagged/apscheduler