Skip to content

asyncio eager tasks' names are set too late #128308

Closed

Description

@graingert

Bug report

Bug description:

consider:

import asyncio

async def main():
    names = []
    async with asyncio.TaskGroup() as tg:
        async def append_name():
            names.append(asyncio.current_task().get_name())

        tg.create_task(append_name(), name="example name")
    print(names)

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

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

this outputs:

['example name']
['Task-5']

but it should output:

['example name']
['example name']

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Dec 28, 2024
  2. kumaraditya303 commented on Jan 8, 2025

    @kumaraditya303
    Contributor

    The task name should be passed when calling the task factory itself otherwise the first eager execution misses the set name.

  3. graingert commented on Jan 8, 2025

    @graingert
    ContributorAuthor

    We should probably just pass the **kwargs without inspection

  4. kumaraditya303 commented on Jan 9, 2025

    @kumaraditya303
    Contributor

    Feel free to propose an PR.

  5. added 2 commits that reference this issue on Jan 13, 2025
  6. graingert commented on Jan 15, 2025

    @graingert
    ContributorAuthor

    Feel free to propose an PR.

    @kumaraditya303 I've proposed a PR

  7. added a commit that references this issue on Jan 20, 2025
  8. moved this from Todo to Done in asyncioon Jan 20, 2025
  9. added a commit that references this issue on Jan 21, 2025
  10. added a commit that references this issue on Feb 13, 2025
  11. added a commit that references this issue on Feb 14, 2025
  12. added a commit that references this issue on May 10, 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/ directorytopic-asynciotype-bugAn unexpected behavior, bug, or error

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions