mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
GH-105684: Require asyncio.Task
implementations to support set_name
method (#105685)
This commit is contained in:
parent
829ac13b69
commit
840d02f3f0
5 changed files with 8 additions and 16 deletions
|
@ -443,7 +443,7 @@ class BaseEventLoop(events.AbstractEventLoop):
|
||||||
else:
|
else:
|
||||||
task = self._task_factory(self, coro, context=context)
|
task = self._task_factory(self, coro, context=context)
|
||||||
|
|
||||||
tasks._set_task_name(task, name)
|
task.set_name(name)
|
||||||
|
|
||||||
return task
|
return task
|
||||||
|
|
||||||
|
|
|
@ -163,7 +163,7 @@ class TaskGroup:
|
||||||
task = self._loop.create_task(coro)
|
task = self._loop.create_task(coro)
|
||||||
else:
|
else:
|
||||||
task = self._loop.create_task(coro, context=context)
|
task = self._loop.create_task(coro, context=context)
|
||||||
tasks._set_task_name(task, name)
|
task.set_name(name)
|
||||||
# optimization: Immediately call the done callback if the task is
|
# optimization: Immediately call the done callback if the task is
|
||||||
# already done (e.g. if the coro was able to complete eagerly),
|
# already done (e.g. if the coro was able to complete eagerly),
|
||||||
# and skip scheduling a done callback
|
# and skip scheduling a done callback
|
||||||
|
|
|
@ -68,19 +68,6 @@ def all_tasks(loop=None):
|
||||||
if futures._get_loop(t) is loop and not t.done()}
|
if futures._get_loop(t) is loop and not t.done()}
|
||||||
|
|
||||||
|
|
||||||
def _set_task_name(task, name):
|
|
||||||
if name is not None:
|
|
||||||
try:
|
|
||||||
set_name = task.set_name
|
|
||||||
except AttributeError:
|
|
||||||
warnings.warn("Task.set_name() was added in Python 3.8, "
|
|
||||||
"the method support will be mandatory for third-party "
|
|
||||||
"task implementations since 3.13.",
|
|
||||||
DeprecationWarning, stacklevel=3)
|
|
||||||
else:
|
|
||||||
set_name(name)
|
|
||||||
|
|
||||||
|
|
||||||
class Task(futures._PyFuture): # Inherit Python Task implementation
|
class Task(futures._PyFuture): # Inherit Python Task implementation
|
||||||
# from a Python Future implementation.
|
# from a Python Future implementation.
|
||||||
|
|
||||||
|
@ -412,7 +399,7 @@ def create_task(coro, *, name=None, context=None):
|
||||||
else:
|
else:
|
||||||
task = loop.create_task(coro, context=context)
|
task = loop.create_task(coro, context=context)
|
||||||
|
|
||||||
_set_task_name(task, name)
|
task.set_name(name)
|
||||||
return task
|
return task
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -243,6 +243,8 @@ class RunTests(BaseTest):
|
||||||
def get_loop(self, *args, **kwargs):
|
def get_loop(self, *args, **kwargs):
|
||||||
return self._task.get_loop(*args, **kwargs)
|
return self._task.get_loop(*args, **kwargs)
|
||||||
|
|
||||||
|
def set_name(self, *args, **kwargs):
|
||||||
|
return self._task.set_name(*args, **kwargs)
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
interrupt_self()
|
interrupt_self()
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Supporting :meth:`asyncio.Task.set_name` is now mandatory for third party task implementations.
|
||||||
|
The undocumented :func:`!_set_task_name` function (deprecated since 3.8) has been removed.
|
||||||
|
Patch by Kumar Aditya.
|
Loading…
Add table
Add a link
Reference in a new issue