Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a3a1cb4

Browse filesBrowse files
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.
1 parent c6e614f commit a3a1cb4
Copy full SHA for a3a1cb4

File tree

Expand file treeCollapse file tree

3 files changed

+7
-6
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+7
-6
lines changed

‎Lib/asyncio/taskgroups.py

Copy file name to clipboardExpand all lines: Lib/asyncio/taskgroups.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ def create_task(self, coro, *, name=None, context=None):
158158
if self._aborting:
159159
raise RuntimeError(f"TaskGroup {self!r} is shutting down")
160160
if context is None:
161-
task = self._loop.create_task(coro)
161+
task = self._loop.create_task(coro, name=name)
162162
else:
163-
task = self._loop.create_task(coro, context=context)
164-
task.set_name(name)
163+
task = self._loop.create_task(coro, name=name, context=context)
164+
165165
# optimization: Immediately call the done callback if the task is
166166
# already done (e.g. if the coro was able to complete eagerly),
167167
# and skip scheduling a done callback

‎Lib/asyncio/tasks.py

Copy file name to clipboardExpand all lines: Lib/asyncio/tasks.py
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,11 +404,10 @@ def create_task(coro, *, name=None, context=None):
404404
loop = events.get_running_loop()
405405
if context is None:
406406
# Use legacy API if context is not needed
407-
task = loop.create_task(coro)
407+
task = loop.create_task(coro, name=name)
408408
else:
409-
task = loop.create_task(coro, context=context)
409+
task = loop.create_task(coro, name=name, context=context)
410410

411-
task.set_name(name)
412411
return task
413412

414413

+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Ensure ``name`` parameter is passed to event loop in
2+
:func:`asyncio.create_task`.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.