-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-128308: pass **kwargs to asyncio task_factory #128768
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
gh-128308: pass **kwargs to asyncio task_factory #128768
Conversation
5b7bf7b
to
0da18e8
Compare
We were somewhat worried about the performance of creating a dict with kwargs and then unpacking it, but it seems pretty similar if not faster: It's a bit slower in the case where we have a name and a factory, which is a bit odd, but most of the time you'd be using a Loop subclass not a factory if you cared about this level of performance. import pyperf
runner = pyperf.Runner()
runner.timeit(
name="create a task with a name",
stmt="loop.create_task(coro(), name='hello')",
setup=["import asyncio; loop = asyncio.EventLoop()", "async def coro(): pass"],
teardown="loop.call_soon(loop.stop); loop.run_forever(); loop.close()",
)
runner.timeit(
name="create a task without a name",
stmt="loop.create_task(coro())",
setup=["import asyncio; loop = asyncio.EventLoop()", "async def coro(): pass"],
teardown="loop.call_soon(loop.stop); loop.run_forever(); loop.close()",
)
runner.timeit(
name="create a task with a name and factory",
stmt="loop.create_task(coro(), name='hello')",
setup=[
"import asyncio; loop = asyncio.EventLoop()",
"def task_factory(loop, coro, **kwargs): return asyncio.Task(coro, loop=loop, **kwargs)",
"loop.set_task_factory(task_factory)",
"async def coro(): pass",
],
teardown="loop.call_soon(loop.stop); loop.run_forever(); loop.close()",
)
runner.timeit(
name="create a task without a name, with a factory",
stmt="loop.create_task(coro())",
setup=[
"import asyncio; loop = asyncio.EventLoop()",
"def task_factory(loop, coro, **kwargs): return asyncio.Task(coro, loop=loop, **kwargs)",
"loop.set_task_factory(task_factory)",
"async def coro(): pass",
],
teardown="loop.call_soon(loop.stop); loop.run_forever(); loop.close()",
) before: 6f167d7
after: 539d2e9
|
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Thanks @graingert for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Sorry, @graingert and @kumaraditya303, I could not cleanly backport this to
|
GH-130084 is a backport of this pull request to the 3.13 branch. |
…onGH-128768) (cherry picked from commit 38a9956) Co-authored-by: Thomas Grainger <tagrain@gmail.com> Co-authored-by: Kumar Aditya <kumaraditya@python.org>
…#130084) * [3.13] gh-128308: pass `**kwargs` to asyncio task_factory (GH-128768) (cherry picked from commit 38a9956) Co-authored-by: Thomas Grainger <tagrain@gmail.com> Co-authored-by: Kumar Aditya <kumaraditya@python.org> --------- Co-authored-by: Thomas Grainger <tagrain@gmail.com> Co-authored-by: Kumar Aditya <kumaraditya@python.org>
why did we break the API spec in a patch release? This caused a sudden breakage for us |
…ry (pythonGH-128768) (python#130084)" This reverts commit 7b0543e.
Uh oh!
There was an error while loading. Please reload this page.