-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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
Conversation
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
3941d4e
to
242ffd2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you also do this for the C accelerator module _asyncio
?
Also, create_task() exists mainly so that e.g. uvloop can override it. Are you sure that uvloop's create_task() takes a name keyword arg?
Thanks for the review @gvanrossum! uvloop does indeed accept a I wasn't able to find an equivalent Please let me know if there is something I missed!
Good point! I was initially worried that custom event loop implementations may be affected if they have never been setting the name initially. Would it be prudent to check if a name is set after calling the loop method and then applying a name (if the kwarg is not None)? E.g. if name and task.get_name() is None:
task.set_name(name) |
Thanks for checking uvloop. And I was fortunately mistaken about This leaves the issue of whether we still need the redundant Unfortunately I also found another place that uses the same pattern: In taskgroups.py there is a It's also unfortunate that Okay, I've got a gut feeling here: let's keep the redundant |
Good spot! To confirm, we won't need |
242ffd2
to
411a760
Compare
@@ -0,0 +1,2 @@ | |||
Ensure ``name`` parameter is passed to event loop in | |||
:func:`asyncio.create_task` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing period.
411a760
to
9f05ba8
Compare
The name parameter is not being passed to the event loop and is instead being set by the asyncio.create_task function. This means that third party implementations of the event loop will never receive the name parameter. This commit fixes this. Note that python3.7 (eol) if the last version of python that does not support the name parameter.
`TaskGroup.create_task` follows the same pattern as `asyncio.create_task`, also including a redundant call to `Task.set_name`. Note that `BaseEventLoop.create_task` uses the `task_factory` if it is set, in which does not accept a `name` kwarg. Hence, while we can remove the redundant call in `TaskGroup` we did not remove it in the `asyncio.create_task`
9f05ba8
to
7d3e88a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, let's drop the redundant set_name()
calls. I'll merge! Thanks for working through this carefully.
Does this need backporting to 3.12? If not, let's close the issue: #112622. |
No backport, it is a slight API change. |
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 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.
Issue: #112622
The name parameter is not being passed to the event loop and is instead being set by the asyncio.create_task function. This means that third party implementations of the event loop will never receive the name parameter. This commit fixes this.
Note Python 3.7 (now end-of-life) is the last version which does not expect a name parameter for
asyncio.create_task
.