Skip to content

Store and use the current task of asyncio on thread state for all threads #129898

@kumaraditya303

Description

@kumaraditya303

asyncio currently stores the current task in a global dict _current_tasks and on thread state. Storing it on dict in free-threading will cause significant contention under many threads and such I propose to remove it and always rely on the task stored on the thread state.

This has the added benefit that external introspection will always have the correct task and it will be guaranteed by this implementation while also being performant.

cc @asvetlov @ambv @pablogsal

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directorytopic-asynciotype-featureA feature request or enhancement

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions