gh-112622: Pass name to loop create_task method (#112623)

This affects task creation through either `asyncio.create_task()` or `TaskGroup.create_task()` -- the redundant call to `task.set_name()` is skipped. We still call `set_name()` when a task factory is involved, because the task factory call signature (unfortunately) doesn't take a `name` argument.
This commit is contained in:
Jamie 2023-12-13 12:26:40 +11:00 committed by GitHub
parent c6e614fd81
commit a3a1cb4845
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 6 deletions

View file

@ -158,10 +158,10 @@ class TaskGroup:
if self._aborting:
raise RuntimeError(f"TaskGroup {self!r} is shutting down")
if context is None:
task = self._loop.create_task(coro)
task = self._loop.create_task(coro, name=name)
else:
task = self._loop.create_task(coro, context=context)
task.set_name(name)
task = self._loop.create_task(coro, name=name, context=context)
# optimization: Immediately call the done callback if the task is
# already done (e.g. if the coro was able to complete eagerly),
# and skip scheduling a done callback