Skip to content

Allow overriding future-task compliance check in asyncio #91323

Description

@asvetlov
BPO 47167
Nosy @asvetlov, @1st1
PRs
  • bpo-47167: Allow overriding a future compliance check in asyncio.Task #32197
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2022-03-30.15:34:50.023>
    labels = ['3.11', 'expert-asyncio']
    title = 'Allow overriding future-task compliance check in  asyncio'
    updated_at = <Date 2022-04-01.02:14:55.054>
    user = 'https://github.com/asvetlov'

    bugs.python.org fields:

    activity = <Date 2022-04-01.02:14:55.054>
    actor = 'yselivanov'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['asyncio']
    creation = <Date 2022-03-30.15:34:50.023>
    creator = 'asvetlov'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 47167
    keywords = ['patch']
    message_count = 3.0
    messages = ['416374', '416467', '416468']
    nosy_count = 2.0
    nosy_names = ['asvetlov', 'yselivanov']
    pr_nums = ['32197']
    priority = 'normal'
    resolution = None
    stage = 'resolved'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue47167'
    versions = ['Python 3.11']

    Activity

    1. asvetlov commented on Mar 30, 2022

      @asvetlov
      ContributorAuthor

      Now asyncio.Task has a strict hardcoded check for futures processes on task's step.
      Sometimes third-party library [1] wants to replace it with custom logic.
      Currently it is impossible without implementing the full asyncio.Task replacement from scratch.
      asyncio.Task is a non-trivial highly optimized part of async, keeping a third-party version in sync with the reference implementation takes more time and effort than it should be.

      This issue proposes adding Task._check_future(future) method that could be overridden in subclasses. The default C implementation uses a fast path that has no performance penalty.

      1. https://github.com/aio-libs/aioloop-proxy implements nested loop proxies that are very useful for writing tests. A proxy can work in parallel with ancestors but checks all own acquired resources cleanup on
        the proxy closing.
    2. asvetlov commented on Apr 1, 2022

      @asvetlov
      ContributorAuthor

      New changeset d4bb38f by Andrew Svetlov in branch 'main':
      bpo-47167: Allow overriding a future compliance check in asyncio.Task (GH-32197)
      d4bb38f

    3. 1st1 commented on Apr 1, 2022

      @1st1
      Member

      Sorry, I don't like the committed change and I think it should be reverted.

      Futures and Tasks have a documented get_loop() method which simply should be called by Task machinery, without the need to expose (and document) private methods.

    4. reopened this on Apr 1, 2022
    5. reopened this on Apr 1, 2022
    6. transferred this issue fromon Apr 10, 2022
    7. graingert commented on Jul 25, 2022

      @graingert
      Contributor

      This patch isn't needed to support the aioloop-proxy use case, you can use an interceptor coroutine to pass the check instead:

      aio-libs/aioloop-proxy@a655652

      this way aioloop proxy works with asyncio.Task CTask PyTask and in addition custom set_task_factory Tasks

    8. added a commit that references this issue on Aug 4, 2022
    9. added a commit that references this issue on Aug 4, 2022
    10. added a commit that references this issue on Aug 4, 2022
    11. kumaraditya303 commented on Oct 9, 2022

      @kumaraditya303
      Contributor

      Closing as the PR was reverted and it is not needed #91323 (comment).

    12. Repository owner moved this from Todo to Done in asyncioon Oct 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      Projects

      • Status
        Done

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions