Closed
Description
Bug report
Bug description:
The name parameter in the asyncio.create_task
function is never passed to the event loop.
Task names are instead only ever set by the asyncio.create_task
function and custom implementations of the event loop will not ever see the task name.
A crude demonstration of this issue is shown below
import asyncio
from unittest import mock
class TestLoop(asyncio.BaseEventLoop):
def create_task(self, coro, *, name=None, context=None):
if coro.__name__ == "sleep":
assert name == "bar"
return super().create_task(coro, name=name, context=context)
class TestPolicy(asyncio.DefaultEventLoopPolicy):
def new_event_loop(self) -> asyncio.AbstractEventLoop:
loop = TestLoop()
loop._process_events = mock.Mock()
loop._write_to_self = mock.Mock()
loop._write_to_self.return_value = None
loop._selector = mock.Mock()
loop._selector.select.return_value = ()
loop.shutdown_ag_run = False
return loop
async def foo():
asyncio.create_task(
asyncio.sleep(0.1),
name="bar",
)
def main():
asyncio.set_event_loop_policy(TestPolicy())
asyncio.run(foo())
if __name__ == "__main__":
main()
CPython versions tested on:
3.12
Operating systems tested on:
macOS
Linked PRs
Metadata
Metadata
Assignees
Projects
Status
Done