Skip to content

asyncio eager tasks' names are set too late #128308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
graingert opened this issue Dec 28, 2024 · 4 comments
Closed

asyncio eager tasks' names are set too late #128308

graingert opened this issue Dec 28, 2024 · 4 comments
Labels
stdlib Python modules in the Lib dir topic-asyncio type-bug An unexpected behavior, bug, or error

Comments

@graingert
Copy link
Contributor

graingert commented Dec 28, 2024

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

@kumaraditya303
Copy link
Contributor

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

@graingert
Copy link
Contributor Author

We should probably just pass the **kwargs without inspection

@kumaraditya303
Copy link
Contributor

Feel free to propose an PR.

@graingert
Copy link
Contributor Author

Feel free to propose an PR.

@kumaraditya303 I've proposed a PR

kumaraditya303 added a commit that referenced this issue Jan 20, 2025
@github-project-automation github-project-automation bot moved this from Todo to Done in asyncio Jan 20, 2025
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Jan 21, 2025
asvetlov pushed a commit to asvetlov/cpython that referenced this issue Feb 13, 2025
…onGH-128768)

(cherry picked from commit 38a9956)

Co-authored-by: Thomas Grainger <[email protected]>
Co-authored-by: Kumar Aditya <[email protected]>
kumaraditya303 added a commit that referenced this issue Feb 14, 2025
…#130084)

* [3.13] gh-128308: pass `**kwargs` to asyncio task_factory (GH-128768)
(cherry picked from commit 38a9956)

Co-authored-by: Thomas Grainger <[email protected]>
Co-authored-by: Kumar Aditya <[email protected]>


---------

Co-authored-by: Thomas Grainger <[email protected]>
Co-authored-by: Kumar Aditya <[email protected]>
kumaraditya303 added a commit to kumaraditya303/cpython that referenced this issue May 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir topic-asyncio type-bug An unexpected behavior, bug, or error
Projects
Status: Done
Development

No branches or pull requests

3 participants