Skip to content

asyncio task_factory does not receive name parameter #113050

@ordinary-jamie

Description

@ordinary-jamie

Bug report

Bug description:

The asyncio.BaseEventLoop.create_task loop method does not pass the name parameter to the task factory

There is two issues with this:

  1. Inconsistent with the eager task factory signature
  2. Users cannot easily configure the task name through just the task factory interface

A simple demonstration of this issue:

import asyncio


def new_task(loop, coro, name=None, context=None):
    assert name is not None  # Will raise

    return asyncio.Task(coro, loop=loop, name=name, context=context)


async def main():
    loop = asyncio.get_event_loop()
    loop.set_task_factory(new_task)
    loop.create_task(asyncio.sleep(1), name="task1")


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

Also see: #112623 (comment)

CPython versions tested on:

3.12

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions