mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-34270: Make it possible to name asyncio tasks (GH-8547)
Co-authored-by: Antti Haapala <antti.haapala@anttipatterns.com>
This commit is contained in:
parent
52dee687af
commit
cca4eec3c0
13 changed files with 266 additions and 28 deletions
|
@ -384,18 +384,20 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
"""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)
|
||||
|
||||
return task
|
||||
|
||||
def set_task_factory(self, factory):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue