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 — Avoid using iterable coroutines in `asyncio` internally · Issue #100112 · python/cpython

Avoid using iterable coroutines in asyncio internally #100112

New issue
Copy link
New issue
Copy link
Closed
Closed
Avoid using iterable coroutines in asyncio internally#100112
Copy link
Assignees
kumaraditya303
Labels
3.12only security fixesonly security fixestopic-asyncio

Description

@kumaraditya303
kumaraditya303
opened on Dec 8, 2022
Issue body actions

asyncio currently uses iterable coroutine directly to wrap awaitables with __await__ methods. This leads to unnecessary special casing and is confusing as asyncio does not supports using yield from now so it should not be used internally too. This will avoid checking for generators everywhere in public APIs (TBD for different issue).

Linked PRs

  • GH-100112: avoid using iterable coroutines in asyncio internally #100128

Activity

  1. kumaraditya303
    added
    topic-asyncio
    3.12only security fixesonly security fixes
    on Dec 8, 2022
  2. ezio-melotti
    added this to asyncioon Dec 8, 2022
  3. ezio-melotti
    moved this to Todo in asyncioon Dec 8, 2022
  4. kumaraditya303 commented on Dec 9, 2022

    @kumaraditya303
    kumaraditya303
    on Dec 9, 2022
    ContributorAuthor
    More actions

    PR #100128 adds a coroutine wrapper around it so that it is not used directly.

  5. kumaraditya303
    self-assigned this
    on Dec 15, 2022
  6. kumaraditya303 commented on Mar 3, 2023

    @kumaraditya303
    kumaraditya303
    on Mar 3, 2023
    ContributorAuthor
    More actions

    More background on this:

    When a custom awaitable object is wrapped by a task, it creates a new iterable coroutine with a generator object as wrapper for the awaitable. This breaks introspection tools which expect a coroutine as they instead get a generator object which is surprising unless you know how things work internally.

    import asyncio
    import inspect
    
    class Awaitable:
        def __await__(self):
            return asyncio.sleep(1).__await__()
    
    async def main():
        task = asyncio.ensure_future(Awaitable())
        coro = task.get_coro()
        print(f"Task created with {coro=}")
        print(inspect.getcoroutinestate(coro))
    
    asyncio.run(main())

    This also somewhat breaks task.get_coro which is expected to return a coroutine object. https://docs.python.org/3/library/asyncio-task.html?highlight=get_coro#asyncio.Task.get_coro

  7. kumaraditya303 commented on Mar 8, 2023

    @kumaraditya303
    kumaraditya303
    on Mar 8, 2023
    ContributorAuthor
    More actions

    @gvanrossum #100128 fixes the above and always returns coroutine. The PR has conflicts but this is the idea behind it.

  8. kumaraditya303 commented on Mar 8, 2023

    @kumaraditya303
    kumaraditya303
    on Mar 8, 2023
    ContributorAuthor
    More actions

    This will also help in allowing generators to accepted in more places like wait etc but that's for different issue.

  9. kumaraditya303
    added a commit that references this issue on Mar 16, 2023

    GH-100112: avoid using iterable coroutines in asyncio internally (#10…

    a44553e
  10. kumaraditya303
    closed this as completedon Mar 16, 2023
  11. github-project-automation
    moved this from Todo to Done in asyncioon Mar 16, 2023
  12. carljm
    added a commit that references this issue on Mar 17, 2023

    Merge branch 'main' into inlinecomp2

    1a8f4a0
  13. Fidget-Spinner
    added a commit that references this issue on Mar 27, 2023

    pythonGH-100112: avoid using iterable coroutines in asyncio internally (

    edd10d0
  14. warsaw
    added a commit that references this issue on Apr 11, 2023

    pythonGH-100112: avoid using iterable coroutines in asyncio internally (

    5c8f788
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @kumaraditya303
    kumaraditya303

Labels

3.12only security fixesonly security fixestopic-asyncio

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.