GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Deprecate asyncio policy system · Issue #127949 · python/cpython

Deprecate asyncio policy system #127949

New issue
Copy link
New issue
Copy link
Closed
Closed
Deprecate asyncio policy system#127949
Copy link
Assignees
kumaraditya303
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotype-featureA feature request or enhancementA feature request or enhancement

Description

@kumaraditya303
kumaraditya303
opened on Dec 14, 2024
Issue body actions

asyncio's policy system deprecation

asyncio's policy system1 has been a source of confusion and problems in asyncio for a very long time. The policies no longer serve a real purpose. Loops are always per thread, there is no need to have a "current loop" when no loop is currently running. This issue discusses the changes to deprecate it in Python 3.14 and schedule its removal in 3.16 or later.

The usual user applications would use the runner APIs (see flowchart) while those who want more control like Jupyter project can create an event loop and manage it themselves, the difference would be that instead of them first getting the policy then event loop then can directly create it like

loop = MyCustomEventLoop()
loop.run_until_complete(task)

rather than currently

asyncio.set_event_loop_policy(MyPolicy())
policy = asyncio.get_event_loop_policy()
loop = policy.new_event_loop()
loop.run_until_complete(task)

See these discussions for more background:

  • Deprecate get_event_loop() #83710 (comment)
  • Finish deprecation in asyncio.get_event_loop() #93453 (comment)
  • deprecate the asyncio child watchers system #94597 (comment)
  • deprecate the asyncio child watchers system #94597
Functions and classes to be deprecated and later removed
  • asyncio.get_event_loop_policy
  • asyncio.set_event_loop_policy
  • asyncio.AbstractEventLoopPolicy
  • asyncio.DefaultEventLoopPolicy
  • asyncio.WindowsSelectorEventLoopPolicy
  • asyncio.WindowsProactorEventLoopPolicy
  • asyncio.set_event_loop
Functions to be modified
  • asyncio.get_event_loop - In 3.16 or later this will become an alias to get_running_loop.
  • asyncio.new_event_loop - In 3.16 or later this will ignore custom policies and will be an alias to asyncio.EventLoop
  • asyncio.run & asyncio.Runner - In 3.16 or later this will be modified to not use policy system as that will be gone and rely solely on loop_factory.

The Grand Plan

  • To minimize changes, all the deprecated functions will be underscored i.e. set_event_loop -> _set_event_loop and set_event_loop will emit the warning then call _set_event_loop as its underlying implementation. This way internally asyncio can still call these functions until they are removed without need of many ignore warnings and the tests too can easily be adapted.
  • The deprecated classes will emit warnings when they are subclassed as it was done for child watchers.
  • The runner APIs will be remain unmodified but making sure that correct warnings are emitted internally when policy system is used.

The Future

---
title: Flowchart for asyncio.run
---
flowchart TD
    A["asyncio.run(coro, loop_factory=...)"] --> B{loop_factory}
    B -->|loop_factory is None| D{platform}
    B -->|loop_factory is not None| E["loop = loop_factory()"]
    D --> |Unix| F["loop = SelectorEventLoop()"]
    D --> |Windows| G["loop = ProactorEventLoop()"]
    E --> H
    F --> H
    G --> H 
    H["loop.run_until_complete(coro)"]
Loading

Linked PRs

  • gh-127949: deprecate asyncio.set_event_loop_policy #128024
  • gh-127949: deprecate asyncio.get_event_loop_policy #128053
  • gh-127949: fix resource warnings in test_tasks.py due to avoiding a call to get_event_loop() #128172
  • gh-127949: fix DeprecationWarning in test_inspect.py #128215
  • gh-127949: deprecate asyncio policy classes #128216
  • gh-127949: deprecate asyncio.set_event_loop #128218
  • gh-127949: add docs for asyncio policy deprecation #128269
  • gh-127949: make deprecation of policy system more prominent #128290
  • [3.13] gh-127949: fix resource warnings in test_tasks.py (GH-128172) #131805
  • [3.12] gh-127949: fix resource warnings in test_tasks.py (GH-128172) #131806
  • gh-127949: remove asyncio policy system #150310

Footnotes

  1. https://docs.python.org/3.14/library/asyncio-policy.html ↩

Reacted by Kirill Podoprigora, Tomas R., Daniel Makhanek, Bénédikt Tran, Roman Kitaev, Ilya Siamionau, Nick Khitrov, Marsel Narbekov, Wulian233, Thomas Grainger and 4 more
Reacted by SoundsSerious

Activity

Next
  1. kumaraditya303
    added
    topic-asyncio
    3.14bugs and security fixesbugs and security fixes
    on Dec 14, 2024
  2. github-project-automation
    added this to asyncioon Dec 14, 2024
  3. github-project-automation
    moved this to Todo in asyncioon Dec 14, 2024
  4. picnixz
    added
    type-featureA feature request or enhancementA feature request or enhancement
    and removed
    3.14bugs and security fixesbugs and security fixes
    on Dec 14, 2024
  5. graingert
    self-assigned this
    on Dec 14, 2024
  6. graingert commented on Dec 14, 2024

    @graingert
    graingert
    on Dec 14, 2024
    Contributor
    More actions

    asyncio.new_event_loop could just be deprecated in favour of asyncio.EventLoop

  7. asvetlov commented on Dec 14, 2024

    @asvetlov
    asvetlov
    on Dec 14, 2024
    Contributor
    More actions

    I support the deprecation in general, details are the subject for future discussion.
    For example, policies are used by very many libraries. It's better for, e.g., maintainers of pytest-asyncio if we keep the deprecation for 5 Python releases (the issue proposes 2 years).
    Let me sleep on other proposed details.
    But anyway, I agree we should deprecate policies at least in a very soft form. If we agree on the 5 year deprecation period we can increase the pressure release-to-release

  8. graingert commented on Dec 15, 2024

    @graingert
    graingert
    on Dec 15, 2024
    Contributor
    More actions

    I support the deprecation in general, details are the subject for future discussion. For example, policies are used by very many libraries. It's better for, e.g., maintainers of pytest-asyncio if we keep the deprecation for 5 Python releases (the issue proposes 2 years). Let me sleep on other proposed details. But anyway, I agree we should deprecate policies at least in a very soft form. If we agree on the 5 year deprecation period we can increase the pressure release-to-release

    how about in 2 years (2 Python releases so 3.16 or 3.27) we swap the default loop_factory for asyncio.Runner and asyncio.run to loop_factory=asyncio.EventLoop This would allow policy users like pytest-asyncio to continue to use asyncio.get_event_loop() with the policy system, but would move most users off the system

  9. kumaraditya303 commented on Dec 15, 2024

    @kumaraditya303
    kumaraditya303
    on Dec 15, 2024
    ContributorAuthor
    More actions

    FTR, asyncio.get_event_loop 1 in Python versions 3.10.0–3.10.8 and 3.11.0, an incorrect deprecation was added for this but it was backed out later because things like asyncio.set_event_loop_policy weren't deprecated at that time.

    With the current plan all of this would be deprecated at the same time so there won't be any issue like that.

    Footnotes

    1. https://docs.python.org/3.11/library/asyncio-eventloop.html#asyncio.get_event_loop check the note ↩

  10. graingert
    assigned
    kumaraditya303
    and unassigned
    graingert
    on Dec 15, 2024
  11. kumaraditya303
    added a commit that references this issue on Dec 18, 2024

    gh-127949: deprecate `asyncio.set_event_loop_policy` (#128024)

    5892853
  12. 27 remaining items

  13. srinivasreddy
    added 2 commits that reference this issue on Jan 8, 2025

    pythongh-127949: add docs for asyncio policy deprecation (python#128269)

    dc60148

    pythongh-127949: make deprecation of policy system more prominent (py…

    51d438e
  14. miss-islington
    added 2 commits that reference this issue on Mar 27, 2025

    pythongh-127949: fix resource warnings in `test_tasks.py` (pythonGH-1…

    ac0688b

    pythongh-127949: fix resource warnings in `test_tasks.py` (pythonGH-1…

    89abf3b
  15. kumaraditya303
    added 2 commits that reference this issue on Mar 28, 2025

    [3.13] gh-127949: fix resource warnings in `test_tasks.py` (GH-128172) (

    924a6ce

    [3.12] gh-127949: fix resource warnings in `test_tasks.py` (GH-128172) (

    d4ddc03
  16. SoundsSerious commented on Apr 29, 2026

    @SoundsSerious
    SoundsSerious
    on Apr 29, 2026 · Hidden as resolved
    show commentMore actions
  17. kumaraditya303 commented on Jun 21, 2026

    @kumaraditya303
    kumaraditya303
    on Jun 21, 2026
    ContributorAuthor
    More actions

    Reopening for the removal of APIs in 3.16

    Reacted by AnubhavB
  18. kumaraditya303
    reopened this on Jun 21, 2026
  19. github-project-automation
    moved this from Done to In Progress in asyncioon Jun 21, 2026
  20. picnixz
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Jun 21, 2026
  21. kumaraditya303
    added a commit that references this issue on Jun 27, 2026

    gh-127949: remove asyncio policy system (#150310)

    b3154aa
  22. kumaraditya303
    closed this as completedon Jun 27, 2026
  23. github-project-automation
    moved this from In Progress to Done in asyncioon Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @kumaraditya303
    kumaraditya303

Labels

extension-modulesC modules in the Modules dirC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotype-featureA feature request or enhancementA feature request or enhancement

Projects

  • asyncio
    Status
    Done
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.