Skip to content
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

Add name keyword argument to loop.create_task() #334

Merged
merged 1 commit into from
Apr 16, 2020

Conversation

fantix
Copy link
Member

@fantix fantix commented Apr 11, 2020

@fantix fantix requested a review from 1st1 April 11, 2020 23:39
# copied from asyncio.tasks._set_task_name (bpo-34270)
if name is not None:
try:
set_name = task.set_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this gain us something over the slightly more readable:

try:
    task.set_name(name)
except AttributeError:
    pass

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't mask an AttributeError coming from the set_name implementation. Which is unlikely but can still happen especially with custom task factories.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion and comments!

I would write something like this:

if name is not None and hasattr(task, "set_name"):
    task.set_name(name)

But this is getting into details (try..except overhead? Two O(1) operations?) and stepping away from the copied code, so I think I'll merge as it is now.

@fantix fantix merged commit d51ce36 into MagicStack:master Apr 16, 2020
@fantix fantix deleted the t309-create-task-name branch April 16, 2020 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: uvloop.loop.create_task() is missing 'name' parameter
3 participants