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 — TaskGroup fails to cancel tasks pending creation, if that task starts a failing task · Issue #128550 · python/cpython

TaskGroup fails to cancel tasks pending creation, if that task starts a failing task #128550

New issue
Copy link
New issue
Copy link
Closed
Closed
TaskGroup fails to cancel tasks pending creation, if that task starts a failing task#128550
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@graingert
graingert
opened on Jan 6, 2025
Issue body actions

Bug report

Bug description:

this 'deadlocks' on eager tasks, but raises an EG as expected on regular 'lazy' tasks.

import sys
import asyncio


if sys.version_info >= (3, 13):
    from asyncio import EventLoop
elif sys.platform == "win32":
    from asyncio import ProactorEventLoop as EventLoop
else:
    from asyncio import SelectorEventLoop as EventLoop


def loop_factory():
    loop = EventLoop()
    loop.set_task_factory(asyncio.eager_task_factory)
    return loop


async def main():
    async with asyncio.TaskGroup() as tg:
        async def third_task():
            raise RuntimeError("third task failed")

        async def second_task():
            tg.create_task(third_task())
            await asyncio.Event().wait()

        tg.create_task(second_task())

# asyncio.run(main())
asyncio.run(main(), loop_factory=loop_factory)

CPython versions tested on:

3.12, 3.13, 3.14

Operating systems tested on:

Linux

Linked PRs

  • gh-128550: TaskGroup: cancel tasks added to set after aborting #128551

Activity

  1. graingert
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    topic-asyncio
    on Jan 6, 2025
  2. github-project-automation
    moved this to Todo in asyncioon Jan 6, 2025
  3. github-project-automation
    added this to asyncioon Jan 6, 2025
  4. graingert
    added 2 commits that reference this issue on Jan 6, 2025

    pythongh-128550: TaskGroup: cancel tasks added to set after aborting

    41929bd

    pythongh-128550: TaskGroup: cancel tasks added to set after aborting

    9726c3d
  5. picnixz
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Jan 6, 2025
  6. kumaraditya303 commented on Jan 20, 2025

    @kumaraditya303
    kumaraditya303
    on Jan 20, 2025
    Contributor
    More actions

    This is happening because as per the following code, we skip scheduling the done callback to the event loop incase the task completes eagerly, I would lean towards fixing this by removing this case and always add the done callback which would be simpler and fix this.

    cpython/Lib/asyncio/taskgroups.py

    Lines 200 to 207 in a30277a

    # optimization: Immediately call the done callback if the task is
    # already done (e.g. if the coro was able to complete eagerly),
    # and skip scheduling a done callback
    if task.done():
    self._on_task_done(task)
    else:
    self._tasks.add(task)
    task.add_done_callback(self._on_task_done)

  7. graingert commented on Jan 20, 2025

    @graingert
    graingert
    on Jan 20, 2025
    ContributorAuthor
    More actions

    @kumaraditya303 do we want this removed on 3.14, 3.13 and 3.12? or just 3.12?

  8. kumaraditya303 commented on Jan 20, 2025

    @kumaraditya303
    kumaraditya303
    on Jan 20, 2025
    Contributor
    More actions

    Yes, all the branches.

  9. graingert commented on Jan 20, 2025

    @graingert
    graingert
    on Jan 20, 2025
    ContributorAuthor
    More actions

    ok will get that setup,

  10. graingert
    added 3 commits that reference this issue on Jan 20, 2025

    pythongh-128550: remove problematic optimization

    efdb97c

    pythongh-128588: pythongh-128550: remove eager tasks optimization tha…

    0fe00b5

    pythongh-128588: pythongh-128550: remove eager tasks optimization tha…

    9fce599
  11. graingert commented on Jan 20, 2025

    @graingert
    graingert
    on Jan 20, 2025
    ContributorAuthor
    More actions

    ok working on news now, looks like it will fix #128588 also

  12. kumaraditya303
    added a commit that references this issue on Jan 20, 2025

    gh-128588: gh-128550: remove eager tasks optimization that missed and…

    ed6934e
  13. miss-islington
    added a commit that references this issue on Jan 20, 2025

    pythongh-128588: pythongh-128550: remove eager tasks optimization tha…

    70fb2d0
  14. kumaraditya303
    added a commit that references this issue on Jan 20, 2025

    [3.13] gh-128588: gh-128550: remove eager tasks optimization that mis…

    a1c48a7
  15. graingert
    added a commit that references this issue on Jan 20, 2025

    pythongh-128588: pythongh-128550: remove eager tasks optimization tha…

    59aff22
  16. srinivasreddy
    added a commit that references this issue on Jan 21, 2025

    pythongh-128588: pythongh-128550: remove eager tasks optimization tha…

    c765847
  17. kumaraditya303
    closed this as completedon Jan 21, 2025
  18. github-project-automation
    moved this from Todo to Done in asyncioon Jan 21, 2025
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

    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    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.