I don’t know why but asyncio.current_task().get_name() returns “None” for every new task once the task exits the task factory function I set, and it only happens in 3.13.
(The same github gist also provices output on 3.9, 3.12 and 3.13, I tested 3.9 to 3.13 and this particular issue only exists in 3.13)
I tried to produce a minimal code that reproduces this behavior… hope someone can take a look at it.
import asyncio
def task_factory(loop, *args, **kwargs):
new_task = asyncio.Task(*args, **kwargs)
name = new_task.get_name()
# Python 3.9 to 3.13 prints name='Task-2'
# 'Task-3' and 'Task-4' is also printed because loop is shutting down, which is not in the scope of (possible) bug
print(f"{name=}")
return new_task
async def print_task_name():
current_task = asyncio.current_task()
name = current_task.get_name()
# Python 3.13 prints name='None' (but why does it print 'Task-2' before it's returned from task_factory() ?)
# Python 3.9 to 3.12 prints name='Task-2'
print(f"{name=}")
async def main():
loop = asyncio.get_running_loop()
loop.set_task_factory(task_factory)
new_task = asyncio.create_task(print_task_name())
await new_task
asyncio.run(main())
I think this is a bug because even if I do something like “different task naming scheme” or subclass asyncio.Task in my custom task_factory(), task’s name gets set to None if no name is passed to asyncio.create_task.