GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-97696: asyncio eager tasks factory by itamaro · Pull Request #102853 · python/cpython

Conversation

@itamaro

@itamaro itamaro commented Mar 20, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

fixes gh-97696

pyperformance results:

  • async tree benchmarks up to ~50% faster when using the eager tasks factory (depending on how many leaf nodes actually suspend)
  • geometric mean for all benchmark 1% faster

pyperformance run performed with local patch that installs the eager tasks factory by default (modifying the benchmark itself to use it requires psf/pyperf#157)

full comparison in this gist

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot mentioned this pull request Mar 20, 2023
Add eager task creation API to asyncio #97696
Closed
@bedevere-bot bedevere-bot added the awaiting review label Mar 20, 2023
@itamaro
itamaro force-pushed the eager-tasks-factory branch from 2a961d3 to 245a52b Compare March 20, 2023 22:21
carljm
carljm reviewed Mar 20, 2023
View reviewed changes
Comment thread Doc/library/asyncio-task.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@itamaro
itamaro force-pushed the eager-tasks-factory branch from 245a52b to bcf40dc Compare March 20, 2023 23:04
@AlexWaygood AlexWaygood added the topic-asyncio label Mar 21, 2023
@itamaro

itamaro commented Mar 21, 2023

Copy link
Copy Markdown
Contributor Author

I'm still chasing a refleak, but otherwise this should be ready for review

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@itamaro
itamaro marked this pull request as ready for review March 21, 2023 03:37
@itamaro
itamaro requested review from 1st1, asvetlov, gvanrossum and kumaraditya303 as code owners March 21, 2023 03:37
gvanrossum
gvanrossum reviewed Mar 21, 2023
View reviewed changes
Comment thread Doc/library/asyncio-task.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@gvanrossum

gvanrossum commented Mar 22, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

It looks like @graingert's observation is a serious problem. How can we fix this?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

itamaro and others added 8 commits April 20, 2023 13:42
@itamaro
Eager task factory implementation
a127f98
@itamaro
Eager task factory tests
45316d8
@itamaro
Add NEWS and docs for eager task factory
ac9b7b0
@itamaro
elaborate explanation in docs and add a whatsnew entry
402c317
@itamaro
fix docs
563ffd4
@itamaro @jbower-fb
Overhaul eager task factory design
6f2a47a
Always create a task object to resolve the design flaw with structured concurrency.
Push the eager step execution into the task implementation, so the task itself knows to eagerly execute the first step if created via the eager task factory.

Co-authored-by: Jacob Bower <[email protected]>
@itamaro
Fix task-counting tests for new impl
e7743f6
@itamaro @jbower-fb
Fix test_task_exc_handler_correct_context
10a03a0
Co-authored-by: Jacob Bower <[email protected]>
@itamaro
itamaro force-pushed the eager-tasks-factory branch from 29d04c2 to 10a03a0 Compare April 21, 2023 03:10
@itamaro
Merge branch 'main' into eager-tasks-factory
5e8ae51
@itamaro itamaro mentioned this pull request Apr 21, 2023
Extend async tree benchmarks to cover eager task execution python/pyperformance#279
Merged
@itamaro

itamaro commented Apr 21, 2023

Copy link
Copy Markdown
Contributor Author

latest version of this PR resolves the issues raised on the issue. tests pass, and rerunning the benchmarks results in pretty much the same results (differences from the original impl within noise margins).

benchmarks ran using pyperformance with this patch.

jbower-fb reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

itamaro added 4 commits April 24, 2023 17:41
@itamaro
Merge branch 'main' into eager-tasks-factory
b4fea1c
@itamaro
add jbower credit
441fd92
@itamaro
cleanup recursive_taskgroups test case
4c46a72
@itamaro
Merge branch 'main' into eager-tasks-factory
8686a3d
@willingc

willingc commented May 1, 2023

Copy link
Copy Markdown
Contributor

@gvanrossum @carljm Could you please take a quick look at this and make sure it resolved your comments? If so, we can merge. Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gvanrossum
gvanrossum approved these changes May 1, 2023
View reviewed changes

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (assuming the refcount leak buildbots are happy). Go ahead without waiting for me with further changes!

PS. Next time please resist the urge to rebase -- it's harder to pick up a review after a rebase has happened. We squash commits when we merge them into main anyways.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

itamaro reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
carljm
carljm reviewed May 1, 2023
View reviewed changes

@carljm carljm left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM barring a couple doc nits and one question.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/asyncio-task.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/asyncio/tasks.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Misc/NEWS.d/next/Library/2023-03-15-12-18-07.gh-issue-97696.DtnpIC.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

itamaro added 5 commits May 1, 2023 09:59
@itamaro
missing word in NEWS entry
0c09767
@itamaro
refactor all_tasks() handling of eager_tasks
a255ec8
@itamaro
fix docs (PR review)
05870d5
@itamaro
move cv.set inside the main task (otherwise it refleaks)
a2587a1
@itamaro
Merge branch 'main' into eager-tasks-factory
0101742
carljm
carljm reviewed May 1, 2023
View reviewed changes
Comment thread Lib/asyncio/tasks.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

itamaro added 2 commits May 1, 2023 11:14
@itamaro
fix grammar in all_tasks comments
b83ed94
@itamaro
Merge branch 'main' into eager-tasks-factory
b17f605
@carljm carljm added the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label May 1, 2023
@bedevere-bot

bedevere-bot commented May 1, 2023

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @carljm for commit b17f605 🤖

If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label May 1, 2023
@carljm
carljm merged commit a474e04 into python:main May 1, 2023
@bedevere-bot bedevere-bot removed the awaiting merge label May 1, 2023
@JelleZijlstra JelleZijlstra mentioned this pull request May 1, 2023
Cannot run tests #104070
Closed
carljm added a commit to carljm/cpython that referenced this pull request May 1, 2023
@carljm
Merge branch 'main' into inlinecomp2
1274e2b
* main: (463 commits)
  pythongh-104057: Fix direct invocation of test_super (python#104064)
  pythongh-87092: Expose assembler to unit tests (python#103988)
  pythongh-97696: asyncio eager tasks factory (python#102853)
  pythongh-84436: Immortalize in _PyStructSequence_InitBuiltinWithFlags() (pythongh-104054)
  pythongh-104057: Fix direct invocation of test_module (pythonGH-104059)
  pythongh-100458: Clarify Enum.__format__() change of mixed-in types in the whatsnew/3.11.rst (pythonGH-100387)
  pythongh-104018: disallow "z" format specifier in %-format of byte strings (pythonGH-104033)
  pythongh-104016: Fixed off by 1 error in f string tokenizer (python#104047)
  pythonGH-103629: Update Unpack's repr in compliance with PEP 692 (python#104048)
  pythongh-102799: replace sys.exc_info by sys.exception in inspect and traceback modules (python#104032)
  Fix typo in "expected" word in few source files (python#104034)
  pythongh-103824: fix use-after-free error in Parser/tokenizer.c (python#103993)
  pythongh-104035: Do not ignore user-defined `__{get,set}state__` in slotted frozen dataclasses (python#104041)
  pythongh-104028: Reduce object creation while calling callback function from gc (pythongh-104030)
  pythongh-104036: Fix direct invocation of test_typing (python#104037)
  pythongh-102213: Optimize the performance of `__getattr__` (pythonGH-103761)
  pythongh-103895: Improve how invalid `Exception.__notes__` are displayed (python#103897)
  Adjust expression from `==` to `!=` in alignment with the meaning of the paragraph. (pythonGH-104021)
  pythongh-88496: Fix IDLE test hang on macOS (python#104025)
  Improve int test coverage (python#104024)
  ...
carljm added a commit to carljm/cpython that referenced this pull request May 2, 2023
@carljm
Merge branch 'main' into cached_property_docs
b9c39e3
* main: (760 commits)
  pythonGH-104102: Optimize `pathlib.Path.glob()` handling of `../` pattern segments (pythonGH-104103)
  pythonGH-104104: Optimize `pathlib.Path.glob()` by avoiding repeated calls to `os.path.normcase()` (pythonGH-104105)
  pythongh-103822: [Calendar] change return value to enum for day and month APIs (pythonGH-103827)
  pythongh-65022: Fix description of tuple return value in copyreg (python#103892)
  pythonGH-103525: Improve exception message from `pathlib.PurePath()` (pythonGH-103526)
  pythongh-84436: Add integration C API tests for immortal objects (pythongh-103962)
  pythongh-103743: Add PyUnstable_Object_GC_NewWithExtraData (pythonGH-103744)
  pythongh-102997: Update Windows installer to SQLite 3.41.2. (python#102999)
  pythonGH-103484: Fix redirected permanently URLs (python#104001)
  Improve assert_type phrasing (python#104081)
  pythongh-102997: Update macOS installer to SQLite 3.41.2. (pythonGH-102998)
  pythonGH-103472: close response in HTTPConnection._tunnel (python#103473)
  pythongh-88496: IDLE - fix another test on macOS (python#104075)
  pythongh-94673: Hide Objects in PyTypeObject Behind Accessors (pythongh-104074)
  pythongh-94673: Properly Initialize and Finalize Static Builtin Types for Each Interpreter (pythongh-104072)
  pythongh-104016: Skip test for deeply neste f-strings on wasi (python#104071)
  pythongh-104057: Fix direct invocation of test_super (python#104064)
  pythongh-87092: Expose assembler to unit tests (python#103988)
  pythongh-97696: asyncio eager tasks factory (python#102853)
  pythongh-84436: Immortalize in _PyStructSequence_InitBuiltinWithFlags() (pythongh-104054)
  ...
kumaraditya303
kumaraditya303 reviewed May 5, 2023
View reviewed changes
Comment thread Modules/_asynciomodule.c
}
} else {
// This seems to really help performance on pyperformance benchmarks
Py_CLEAR(task->task_coro);

@kumaraditya303 kumaraditya303 May 5, 2023

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this documented anywhere? I can't find it

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@itamaro itamaro May 5, 2023

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbower-fb

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jbower-fb jbower-fb May 5, 2023

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comments on #97696.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jbower-fb jbower-fb May 5, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also #104304 as possible documentation.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
kumaraditya303
kumaraditya303 reviewed May 5, 2023
View reviewed changes
Comment thread Lib/asyncio/tasks.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@jbower-fb jbower-fb mentioned this pull request May 5, 2023
gh-97696 Remove unnecessary check for eager_start kwarg #104188
Merged
kumaraditya303
kumaraditya303 reviewed May 5, 2023
View reviewed changes
Comment thread Modules/_asynciomodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@jbower-fb jbower-fb mentioned this pull request May 5, 2023
gh-97696: Remove redundant #include #104216
Merged
kumaraditya303
kumaraditya303 reviewed May 6, 2023
View reviewed changes
Comment thread Modules/_asynciomodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

itamaro added a commit to itamaro/cpython that referenced this pull request May 7, 2023
@itamaro
pythongh-97696: Use PyObject_CallMethodNoArgs and inline is_loop_runn…
20048db
…ing check

based on feedback from python#102853 (review)
@itamaro itamaro mentioned this pull request May 7, 2023
gh-97696: Use PyObject_CallMethodNoArgs and inline is_loop_running check #104255
Merged
@itamaro
itamaro deleted the eager-tasks-factory branch May 7, 2023 22:16
@willingc

willingc commented May 9, 2023

Copy link
Copy Markdown
Contributor

Great to see this land @itamaro. Thanks for being so collaborative on working through the PR. 🎉

itamaro reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Dreamsorcerer

Dreamsorcerer commented Aug 8, 2024

Copy link
Copy Markdown
Contributor

The proposal at the start of this thread suggested a new method or parameter for eager start. Is there a link to any discussion on why this changed? Are there plans to do something like that in future (or just to make it the default, and remove the old behaviour)?

I'm thinking about this from a library side. Changing the global task factory is inappropriate for a library to do, but we still have certain tasks that would strongly benefit from eager execution (I also wonder if a user enabling this globally could end up breaking a library that wasn't expecting eager tasks...).

So, some way to execute individual tasks eagerly would be useful (unless it simply becomes the default behaviour). We currently instantiate Task(eager_start=True) directly, though the docs seem to strongly discourage this. Adding an eager_start to asyncio.create_task(), or maybe some way to temporarily change task factories (with eager_task_factory:) would be ideal.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@carljm carljm carljm left review comments
@gvanrossum gvanrossum gvanrossum approved these changes
@kumaraditya303 kumaraditya303 kumaraditya303 left review comments
@willingc willingc willingc approved these changes
@1st1 1st1 Awaiting requested review from 1st1 1st1 is a code owner
@asvetlov asvetlov Awaiting requested review from asvetlov asvetlov is a code owner
+1 more reviewer
@jbower-fb jbower-fb jbower-fb left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

topic-asyncio

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Add eager task creation API to asyncio

Uh oh!

There was an error while loading. Please reload this page.

9 participants

@itamaro @gvanrossum @willingc @bedevere-bot @Dreamsorcerer @carljm @jbower-fb @kumaraditya303 @AlexWaygood
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.