diff options
author | Thomas Grainger <tagrain@gmail.com> | 2025-01-20 16:53:55 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-20 22:23:55 +0530 |
commit | 38a99568763604ccec5d5027f0658100ad76876f (patch) | |
tree | ac5647d46bea82576efb46eef1eb49868929faf4 /Lib/asyncio/base_events.py | |
parent | 6c914bf85cc3a07e22e4618d0b5607c158e3cf66 (diff) | |
download | cpython-38a99568763604ccec5d5027f0658100ad76876f.tar.gz cpython-38a99568763604ccec5d5027f0658100ad76876f.zip |
gh-128308: pass `**kwargs` to asyncio task_factory (#128768)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Diffstat (limited to 'Lib/asyncio/base_events.py')
-rw-r--r-- | Lib/asyncio/base_events.py | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index 85018797db3..ed852421e44 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -458,25 +458,18 @@ class BaseEventLoop(events.AbstractEventLoop): """Create a Future object attached to the loop.""" return futures.Future(loop=self) - def create_task(self, coro, *, name=None, context=None): + def create_task(self, coro, **kwargs): """Schedule a coroutine object. Return a task object. """ self._check_closed() - if self._task_factory is None: - task = tasks.Task(coro, loop=self, name=name, context=context) - if task._source_traceback: - del task._source_traceback[-1] - else: - if context is None: - # Use legacy API if context is not needed - task = self._task_factory(self, coro) - else: - task = self._task_factory(self, coro, context=context) - - task.set_name(name) + if self._task_factory is not None: + return self._task_factory(self, coro, **kwargs) + task = tasks.Task(coro, loop=self, **kwargs) + if task._source_traceback: + del task._source_traceback[-1] try: return task finally: @@ -490,9 +483,10 @@ class BaseEventLoop(events.AbstractEventLoop): If factory is None the default task factory will be set. If factory is a callable, it should have a signature matching - '(loop, coro)', where 'loop' will be a reference to the active - event loop, 'coro' will be a coroutine object. The callable - must return a Future. + '(loop, coro, **kwargs)', where 'loop' will be a reference to the active + event loop, 'coro' will be a coroutine object, and **kwargs will be + arbitrary keyword arguments that should be passed on to Task. + The callable must return a Task. """ if factory is not None and not callable(factory): raise TypeError('task factory must be a callable or None') |