Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions Lib/asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,16 +458,26 @@ def create_future(self):
"""Create a Future object attached to the loop."""
return futures.Future(loop=self)

def create_task(self, coro, **kwargs):
def create_task(self, coro, *, name=None, context=None, **kwargs):
"""Schedule a coroutine object.

Return a task object.
"""
self._check_closed()
if self._task_factory is not None:
return self._task_factory(self, coro, **kwargs)
if context is not None:
kwargs["context"] = context

task = tasks.Task(coro, loop=self, **kwargs)
task = self._task_factory(self, coro, **kwargs)
task.set_name(name)
try:
# gh-128552: prevent a refcycle of
# task.exception().__traceback__->BaseEventLoop.create_task->task
return task
finally:
del task

task = tasks.Task(coro, loop=self, name=name, context=context, **kwargs)
if task._source_traceback:
del task._source_traceback[-1]
try:
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_asyncio/test_taskgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,7 @@ async def throw_error():
# cancellation happens here and error is more understandable
await asyncio.sleep(0)

@unittest.expectedFailure
async def test_name(self):
name = None

Expand Down
Loading