8000 gh-97696: asyncio eager tasks factory by itamaro · Pull Request #102853 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-97696: asyncio eager tasks factory #102853

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

Merged
merged 38 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a127f98
Eager task factory implementation
itamaro Mar 20, 2023
45316d8
Eager task factory tests
itamaro Mar 20, 2023
ac9b7b0
Add NEWS and docs for eager task factory
itamaro Mar 20, 2023
402c317
elaborate explanation in docs and add a whatsnew entry
itamaro Mar 22, 2023
563ffd4
fix docs
itamaro Mar 22, 2023
6f2a47a
Overhaul eager task factory design
itamaro Apr 20, 2023
e7743f6
Fix task-counting tests for new impl
itamaro Apr 20, 2023
10a03a0
Fix test_task_exc_handler_correct_context
itamaro Apr 21, 2023
5e8ae51
Merge branch 'main' into eager-tasks-factory
itamaro Apr 21, 2023
b4fea1c
Merge branch 'main' into eager-tasks-factory
itamaro Apr 24, 2023
441fd92
add jbower credit
itamaro Apr 24, 2023
4c46a72
cleanup recursive_taskgroups test case
itamaro Apr 24, 2023
8686a3d
Merge branch 'main' into eager-tasks-factory
itamaro Apr 25, 2023
14b6f58
Update asyncio documentation with latest state of the PR
itamaro Apr 25, 2023
0f9185c
don't add coro to the task repr if coro is None
itamaro Apr 25, 2023
679534a
also update the NEWS entry
itamaro Apr 25, 2023
70bb3d4
add error check when using _PyDict_GetItem_KnownHash in swap_current_…
itamaro Apr 25, 2023
7edcf3f
focus the eager task factory test suite on testing eager execution se…
itamaro Apr 25, 2023
45e5c8c
ensure task_eager_start is not called with a NULL task
itamaro Apr 25, 2023
fbf8d91
Refactor eager task tests to clarify the "loop is running" constraint…
itamaro Apr 26, 2023
873a645
Apply documentation suggestions and feedback
itamaro Apr 26, 2023
9c2bc9a
Merge remote-tracking branch 'upstream/main' into eager-tasks-factory
itamaro Apr 26, 2023
9522c54
fix docs (rst is hard)
itamaro Apr 26, 2023
2acdc51
Merge branch 'main' into eager-tasks-factory
itamaro Apr 27, 2023
fef8140
Extend eager task factory tests
jbower-fb Apr 28, 2023
1eb540c
a little cleanup of newly added tests
itamaro Apr 28, 2023
3cef856
add assertion to current_task test, comparing the task before and aft…
itamaro Apr 28, 2023
8877716
add a second step to contextvars test
itamaro Apr 28, 2023
57ccce3
Merge branch 'main' into eager-tasks-factory
itamaro Apr 28, 2023
57b197f
Merge branch 'main' into eager-tasks-factory
willingc Apr 28, 2023
c545645
Merge branch 'main' into eager-tasks-factory
itamaro Apr 30, 2023
0c09767
missing word in NEWS entry
itamaro May 1, 2023
a255ec8
refactor all_tasks() handling of eager_tasks
itamaro May 1, 2023
05870d5
fix docs (PR review)
itamaro May 1, 2023
a2587a1
move cv.set inside the main task (otherwise it refleaks)
itamaro May 1, 2023
0101742
Merge branch 'main' into eager-tasks-factory
itamaro May 1, 2023
b83ed94
fix grammar in all_tasks comments
itamaro May 1, 2023
b17f605
Merge branch 'main' into eager-tasks-factory
itamaro May 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
elaborate explanation in docs and add a whatsnew entry
  • Loading branch information
itamaro committed Apr 20, 2023
commit 402c3172dc2942642f2929943bd3982388b25e64
14 changes: 12 additions & 2 deletions Doc/library/asyncio-task.rst
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,20 @@ Eager Task Factory
A task factory for eager task execution.

When using this factory (via ``loop.set_task_factory(asyncio.eager_task_factory)``),
coroutines that are able to complete synchronously (without suspending)
coroutines that are able to complete synchronously (without blocking)
are returned immediately as a completed :class:`Future`.

A regular :class:`Task` is returned otherwise, at the first suspension of *coro*.
This task factory tries to execute the coroutine `coro` immediately
(before creating and scheduling a task to the event loop), until it either
blocks, returns, or raises.
If the coroutine returns or raises, a :class:`Future` is returned, and no
task is created or scheduled to the event loop. If the coroutine blocks,
a :class:`Task` is constructed and returned at that point.

.. note::

The fact that the coroutine starts execution immediately is a semantic change,
and might lead to application behavior changes, depending on the application.

.. versionadded:: 3.12

Expand Down
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,11 @@ Optimizations
replacement strings containing group references by 2--3 times.
(Contributed by Serhiy Storchaka in :gh:`91524`.)

* Added :func:`asyncio.eager_task_factory` and :func:`asyncio.create_eager_task_factory`
functions to allow opting an event loop in to eager task execution,
speeding up some use-cases by up to 50%.
(Contributed by Itamar O in :gh:`102853`)


CPython bytecode changes
========================
Expand Down
0