Skip to content

custom task factory and _PyTask fails to register task. #140050

@kristjanvalur

Description

@kristjanvalur

Bug report

Bug description:

Python 3.14 contains a regression, in which _PyTask objects created with a custom task factory fail to register as a current task. The following code asserts on python 3.14 while succeeding on 3.13.

import asyncio


def custom_factory(loop, coro, **kwargs):
    from asyncio.tasks import _PyTask
    return _PyTask(coro, loop=loop, **kwargs)


async def check_current_task():
    task = asyncio.current_task()
    assert task is not None, "asyncio.current_task() returned None"
    return task


async def main():
    loop = asyncio.get_running_loop()
    loop.set_task_factory(custom_factory)
    
    task = loop.create_task(check_current_task())
    result = await task
    
    print(f"Success: {result}")


if __name__ == "__main__":
    asyncio.run(main())

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedstdlibStandard 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