Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-128307: support eager_start kwarg in create_eager_task_factory, and pass kwargs from asyncio.create_task and TaskGroup.create_task#128306
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
23d2c42da5cab37bce4018ad26fc90f9ef21107608ec3bd14939c3f5d24d43bd8369c34a4ad1b813398cdfafc7a3175aae05988773e8e2a81c100635288bf214e053673a20a5c92e2fa8aab5f1a4101251a45d437654a8574b02d4File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -459,7 +459,7 @@ def create_future(self): | ||
| return futures.Future(loop=self) | ||
| def create_task(self, coro, **kwargs): | ||
| """Schedule a coroutine object. | ||
| """Schedule or begin executing a coroutine object. | ||
graingert marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| Return a task object. | ||
| """ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -386,19 +386,13 @@ def __wakeup(self, future): | ||
| Task = _CTask = _asyncio.Task | ||
| def create_task(coro, *, name=None, context=None): | ||
| def create_task(coro, **kwargs): | ||
Contributor 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. From the Python user perspective, I don't like this change. I suppose we'd be relying on https://github.com/python/typeshed/blob/main/stdlib/asyncio/tasks.pyi from now on? Member 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. I agree it would be nice if we could avoid the IDEs should be using typeshed anyway. (And we should update tasks.pyi to have a case for 3.14 that adds | ||
| """Schedule the execution of a coroutine object in a spawn task. | ||
graingert marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| Return a Task object. | ||
| """ | ||
| loop = events.get_running_loop() | ||
| if context is None: | ||
| # Use legacy API if context is not needed | ||
| task = loop.create_task(coro, name=name) | ||
| else: | ||
| task = loop.create_task(coro, name=name, context=context) | ||
| return task | ||
| return loop.create_task(coro, **kwargs) | ||
| # wait() and as_completed() similar to those in PEP 3148. | ||
| @@ -1030,9 +1024,9 @@ def create_eager_task_factory(custom_task_constructor): | ||
| used. E.g. `loop.set_task_factory(asyncio.eager_task_factory)`. | ||
| """ | ||
| def factory(loop, coro, *, name=None, context=None): | ||
| def factory(loop, coro, *, eager_start=True, **kwargs): | ||
| return custom_task_constructor( | ||
| coro, loop=loop, name=name, context=context, eager_start=True) | ||
| coro, loop=loop, eager_start=eager_start, **kwargs) | ||
| return factory | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -263,6 +263,24 @@ async def run(): | ||
| self.run_coro(run()) | ||
| def test_eager_start_false(self): | ||
| name = None | ||
| async def asyncfn(): | ||
| nonlocal name | ||
| name = asyncio.current_task().get_name() | ||
| async def main(): | ||
| t = asyncio.get_running_loop().create_task( | ||
| asyncfn(), eager_start=False, name="example" | ||
| ) | ||
| self.assertFalse(t.done()) | ||
| self.assertIsNone(name) | ||
| await t | ||
| self.assertEqual(name, "example") | ||
| self.run_coro(main()) | ||
| class PyEagerTaskFactoryLoopTests(EagerTaskFactoryLoopTests, test_utils.TestCase): | ||
| Task = tasks._PyTask | ||
| @@ -505,5 +523,24 @@ def tearDown(self): | ||
| asyncio.current_task = asyncio.tasks.current_task = self._current_task | ||
| return super().tearDown() | ||
| class DefaultTaskFactoryEagerStart(test_utils.TestCase): | ||
| def test_eager_start_true_with_default_factory(self): | ||
| name = None | ||
| async def asyncfn(): | ||
| nonlocal name | ||
| name = asyncio.current_task().get_name() | ||
| async def main(): | ||
| t = asyncio.get_running_loop().create_task( | ||
| asyncfn(), eager_start=True, name="example" | ||
| ) | ||
| self.assertTrue(t.done()) | ||
graingert marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| self.assertEqual(name, "example") | ||
| await t | ||
| asyncio.run(main(), loop_factory=asyncio.EventLoop) | ||
| if __name__ == '__main__': | ||
| unittest.main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add ``eager_start`` keyword argument to :meth:`asyncio.loop.create_task` |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.