Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Lib/asyncio/taskgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ def create_task(self, coro, *, name=None, context=None):
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
Expand Down
5 changes: 2 additions & 3 deletions Lib/asyncio/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,10 @@ def create_task(coro, *, name=None, context=None):
loop = events.get_running_loop()
if context is None:
# Use legacy API if context is not needed
task = loop.create_task(coro)
task = loop.create_task(coro, name=name)
else:
task = loop.create_task(coro, context=context)
task = loop.create_task(coro, name=name, context=context)

task.set_name(name)
return task


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Ensure ``name`` parameter is passed to event loop in
:func:`asyncio.create_task`.