Skip to content

gh-140414: add fastpath for current running loop in asyncio.all_tasks#140542

Merged
kumaraditya303 merged 3 commits intopython:mainfrom
kumaraditya303:all-tasks
Oct 24, 2025
Merged

gh-140414: add fastpath for current running loop in asyncio.all_tasks#140542
kumaraditya303 merged 3 commits intopython:mainfrom
kumaraditya303:all-tasks

Conversation

@kumaraditya303
Copy link
Contributor

@kumaraditya303 kumaraditya303 commented Oct 24, 2025

Optimize asyncio.all_tasks() for the common case where the event loop is running in the current thread by avoiding stop-the-world pause and locking. This optimization is already present for asyncio.current_task() so we do the same for asyncio.all_tasks().

… is running

in the current thread by avoiding stop-the-world pauses and locking.

This optimization is already present for asyncio.current_task() so we
do the same for asyncio.all_tasks().
Copy link
Contributor

@colesbury colesbury left a comment

Choose a reason for hiding this comment

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

LGTM

Co-authored-by: Sam Gross <colesbury@gmail.com>
@kumaraditya303 kumaraditya303 merged commit 95e5d59 into python:main Oct 24, 2025
43 checks passed
@kumaraditya303 kumaraditya303 deleted the all-tasks branch October 24, 2025 14:32
StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
…l_tasks` (python#140542)

Optimize `asyncio.all_tasks()` for the common case where the event loop is running in the current thread by avoiding stop-the-world pauses and locking.

This optimization is already present for `asyncio.current_task()` so we do the same for `asyncio.all_tasks()`.
@kumaraditya303 kumaraditya303 added the needs backport to 3.14 bugs and security fixes label Feb 5, 2026
@miss-islington-app
Copy link

Thanks @kumaraditya303 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 5, 2026
…l_tasks` (pythonGH-140542)

Optimize `asyncio.all_tasks()` for the common case where the event loop is running in the current thread by avoiding stop-the-world pauses and locking.

This optimization is already present for `asyncio.current_task()` so we do the same for `asyncio.all_tasks()`.
(cherry picked from commit 95e5d59)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
@bedevere-app
Copy link

bedevere-app bot commented Feb 5, 2026

GH-144494 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Feb 5, 2026
kumaraditya303 added a commit that referenced this pull request Feb 6, 2026
…ll_tasks` (GH-140542) (#144494)

* gh-140414: add fastpath for current running loop in `asyncio.all_tasks` (GH-140542)

Optimize `asyncio.all_tasks()` for the common case where the event loop is running in the current thread by avoiding stop-the-world pauses and locking.

This optimization is already present for `asyncio.current_task()` so we do the same for `asyncio.all_tasks()`.
(cherry picked from commit 95e5d59)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants