Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

graingert
Copy link
Contributor

@graingertgraingert commentedJan 13, 2025
edited by bedevere-appbot
Loading

@graingertgraingertforce-pushed thepass-kwargs-to-task-factory branch from5b7bf7b to0da18e8CompareJanuary 13, 2025 07:49
@graingert
Copy link
ContributorAuthor

graingert commentedJan 20, 2025
edited
Loading

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.

importpyperfrunner=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

.....................create a task with a name: Mean +- std dev: 1.27 us +- 0.10 us.....................create a task without a name: Mean +- std dev: 1.29 us +- 0.10 us.....................create a task with a name and factory: Mean +- std dev: 1.28 us +- 0.10 us.....................create a task without a name, with a factory: Mean +- std dev: 1.34 us +- 0.10 us

after:539d2e9

.....................create a task with a name: Mean +- std dev: 1.25 us +- 0.09 us.....................create a task without a name: Mean +- std dev: 1.22 us +- 0.10 us.....................create a task with a name and factory: Mean +- std dev: 1.53 us +- 0.11 us.....................create a task without a name, with a factory: Mean +- std dev: 1.32 us +- 0.10 us

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
@kumaraditya303kumaraditya303 merged commit38a9956 intopython:mainJan 20, 2025
44 checks passed
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull requestJan 21, 2025
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
@asvetlovasvetlov added the needs backport to 3.13bugs and security fixes labelFeb 13, 2025
@miss-islington-app
Copy link

Thanks@graingert for the PR, and@kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry,@graingert and@kumaraditya303, I could not cleanly backport this to3.13 due to a conflict.
Please backport usingcherry_picker on command line.

cherry_picker 38a99568763604ccec5d5027f0658100ad76876f 3.13

@bedevere-app
Copy link

GH-130084 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelFeb 13, 2025
asvetlov pushed a commit to asvetlov/cpython that referenced this pull requestFeb 13, 2025
…onGH-128768)(cherry picked from commit38a9956)Co-authored-by: Thomas Grainger <tagrain@gmail.com>Co-authored-by: Kumar Aditya <kumaraditya@python.org>
kumaraditya303 added a commit that referenced this pull requestFeb 14, 2025
…#130084)* [3.13]gh-128308: pass `**kwargs` to asyncio task_factory (GH-128768)(cherry picked from commit38a9956)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>
@graingertgraingert deleted the pass-kwargs-to-task-factory branchMarch 20, 2025 16:33
@johng
Copy link

why did we break the API spec in a patch release? This caused a sudden breakage for us

alicederyn and godlygeek reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@kumaraditya303kumaraditya303kumaraditya303 approved these changes

@1st11st1Awaiting requested review from 1st11st1 is a code owner

@asvetlovasvetlovAwaiting requested review from asvetlovasvetlov is a code owner

@willingcwillingcAwaiting requested review from willingcwillingc is a code owner

Assignees

@kumaraditya303kumaraditya303

Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@graingert@johng@kumaraditya303@asvetlov

[8]ページ先頭

©2009-2025 Movatter.jp