-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
bpo-34270: added the ability to name asyncio tasks #8547
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
Changes from all commits
19204e1
25939b9
369eba9
ce8e014
11258ed
1f3dda6
de125ce
98ebde1
5aadb36
ad5c572
5fba009
fc02fd4
77f2147
645b638
b352983
56e2883
d655f24
dd4d4a5
860d67a
2cca5e7
a1be2e0
2ee3972
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -381,18 +381,20 @@ def create_future(self): | |
"""Create a Future object attached to the loop.""" | ||
return futures.Future(loop=self) | ||
|
||
def create_task(self, coro): | ||
def create_task(self, coro, *, name=None): | ||
"""Schedule a coroutine object. | ||
|
||
Return a task object. | ||
""" | ||
self._check_closed() | ||
if self._task_factory is None: | ||
task = tasks.Task(coro, loop=self) | ||
task = tasks.Task(coro, loop=self, name=name) | ||
if task._source_traceback: | ||
del task._source_traceback[-1] | ||
else: | ||
task = self._task_factory(self, coro) | ||
tasks._set_task_name(task, name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line should be unindented or you should pass the name to |
||
|
||
return task | ||
|
||
def set_task_factory(self, factory): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,13 @@ def _task_repr_info(task): | |
# replace status | ||
info[0] = 'cancelling' | ||
|
||
info.insert(1, 'name=%r' % task.get_name()) | ||
|
||
coro = coroutines._format_coroutine(task._coro) | ||
info.insert(1, f'coro=<{coro}>') | ||
info.insert(2, f'coro=<{coro}>') | ||
|
||
if task._fut_waiter is not None: | ||
info.insert(2, f'wait_for={task._fut_waiter!r}') | ||
info.insert(3, f'wait_for={task._fut_waiter!r}') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, feel free to make another pull request to refactor this code. I don't like us modifying some list object with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would you prefer that we display the name of the task in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be great to refactor the code that formats things (tasks, callbacks, reprs) etc somehow. Right now it feels hacky and it's one of the areas of asyncio code that I'd like to be rewritten to be clearer. Discussing that is slightly out of the scope of this PR though, but if you have any ideas how to avoid mutating lists and having a non-linear formatting logic I'd be happy to accept a new PR. For this PR, your current code is totally fine! |
||
return info | ||
|
||
|
||
|
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.
We also need to update the documentation of
set_task_factory
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.
Good point.