apscheduler

agronholmMIT活跃维护

Python 任务调度库,支持 cron、间隔和一次性任务,可把定时作业挂到后台运行,省去自己写调度循环。

Task scheduling library for Python

3.11.3发布于 2026-06-28 19:39 UTC7,700star +7 / 7 天821fork同步于 2026-11-10 23:33 UTC

怎么上手

由 README 提炼,执行前请确认
pip install apscheduler
硬件要求按 README 说明

README 未说明

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

Python 任务调度与任务队列库,支持单机到多节点部署,同步异步皆可

Python 任务调度库,支持 cron、间隔和一次性任务,可把定时作业挂到后台运行,省去自己写调度循环。

核心能力

  • 提供同步与异步两种风格,适配线程和 asyncio/Trio 应用
  • 支持 Cron、间隔、日历、一次性及组合触发器
  • 内置 PostgreSQL、MySQL、SQLite、MongoDB 持久化存储
  • 多调度器与 worker 共享数据存储,实现高可用与横向扩展
  • 可限制并发任务数、允许延迟启动时长并加入随机抖动

容易踩的坑

v4.0 系列为预发布版,可能不兼容变更,README 明确警告勿用于生产;多调度器或多 worker 场景需额外配置事件代理(PostgreSQL/Redis/MQTT)

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本3.11.3
  1. 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 ZoneInfo time 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)
  2. 3.11.22025-12-22 · 2025-12-22 00:39 UTC
    查看更新说明
    • Fixed an issue where a job using a CronTrigger scheduled in a repeated time interval during DST transitions could cause the scheduler to get stuck in an infinite loop (#1021; PR by @soulofakuma)
  3. 3.11.12025-10-31 · 2025-10-31 18:55 UTC
    查看更新说明
    • Fixed scheduler.shutdown() not raising SchedulerNotRunning (or raising the wrong exception) for asynchronous schedulers when the scheduler is in fact not running
    • Fixed CronTrigger sticking on a folded datetime during the fall-back DST transition (#1021 <https://github.com/agronholm/apscheduler/issues/1021>_; PR by @berianjames)`
  4. 4.0.0a62025-04-27 · 2025-04-27 08:36 UTC
    查看更新说明
    • BREAKING Refactored AsyncpgEventBroker to directly accept a connection string, thus eliminating the need for the AsyncpgEventBroker.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 Task and Schedule classes to be read-only
    • BREAKING Refactored the release_schedules() data store method to take a sequence of ScheduleResult instances 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_delay parameter with a new scheduler-level parameter, lease_duration which is then used to call the various data store methods
    • BREAKING Added the job_result_expiration_time field to the Schedule class, to allow the job results from scheduled jobs to stay around for some time (#927)
    • BREAKING Added an index for the created_at job field, so acquiring jobs would be faster when there are a lot of them
    • BREAKING Removed the job_executor and max_running_jobs parameters from add_schedule() and add_run_job() (explicitly configure the task using configure_task() or by using the new @task decorator
    • BREAKING Replaced the default_job_executor scheduler parameter with a more comprehensive task_defaults parameter
    • Added the @task decorator 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 timezone argument to CronTrigger.from_crontab() into a keyword-only argument
    • BREAKING Added the metadata field to tasks, schedules and jobs
    • BREAKING Added logic to store last_fire_time in datastore implementations (PR by @hlobit)
    • BREAKING Added the reap_abandoned_jobs() abstract method to DataStore which 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_time and end_time arguments to CronTrigger.from_crontab() (#676)
    • Added the psycopg event broker
    • Added useful indexes and removed useless ones in SQLAlchemyDatastore and MongoDBDataStore
    • Changed the lock_expiration_delay parameter of built-in data stores to accept a timedelta as well as int or float
    • Fixed serialization error with CronTrigger when pausing a schedule (#864)
    • Fixed TypeError: object NoneType can't be used in 'await' expression at teardown of SQLAlchemyDataStore when it was passed a URL that implicitly created a synchronous engine
    • Fixed serializers raising their own exceptions instead of SerializationError and DeserializationError as appropriate
    • Fixed repr() outputs of schedulers, data stores and event brokers to be much more useful and reasonable
    • Fixed race condition in MongoDBDataStore that allowed multiple schedulers to acquire the same schedules at once
    • Changed SQLAlchemyDataStore to automatically create the explicitly specified schema if it's missing (PR by @zhu0629)
    • Fixed an issue with CronTrigger infinitely looping to get next date when DST
  5. 3.11.02024-11-24 · 2024-11-24 19:42 UTC
    查看更新说明
    • Dropped support for Python 3.6 and 3.7
    • Added support for ZoneInfo time 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() and scheduler.import_jobs(), respectively
    • Removed the dependency on six
    • Changed ProcessPoolExecutor to spawn new subprocesses from scratch instead of forking on all platform
    • Fixed AsyncIOScheduler inadvertently creating a defunct event loop at start, leading to the scheduler not working at all
    • Fixed ProcessPoolExecutor not respecting the passed keyword arguments when a broken pool was being replaced

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    .. 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 apscheduler tag

    .. _GitHub discussions: https://github.com/agronholm/apscheduler/discussions/categories/q-a .. _StackOverflow: http://stackoverflow.com/questions/tagged/apscheduler