diff options
author | Kumar Aditya <kumaraditya@python.org> | 2025-02-19 22:04:49 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-19 16:34:49 +0000 |
commit | 660f126f870535b6fa607e6d9cdd3cdbd9ed2cb1 (patch) | |
tree | 3c37bf428ac66f977f865236434758ad57d05a76 /Lib/asyncio/tasks.py | |
parent | fb17f41522718013036ce44cbe83a72f5d9a2104 (diff) | |
download | cpython-660f126f870535b6fa607e6d9cdd3cdbd9ed2cb1.tar.gz cpython-660f126f870535b6fa607e6d9cdd3cdbd9ed2cb1.zip |
gh-129898: per-thread current task implementation in asyncio (#129899)
Store the current running task on the thread state, it makes it thread safe for the free-threading build and while improving performance as there is no lock contention, this effectively makes it lock free.
When accessing the current task of the current running loop in current thread, no locking is required and can be acessed without locking.
In the rare case of accessing current task of a loop running in a different thread, the stop the world pauses is used in free-threading builds to stop all other running threads and find the task for the specified loop.
This also makes it easier for external introspection to find the current task, and now it will be always correct.
Diffstat (limited to 'Lib/asyncio/tasks.py')
-rw-r--r-- | Lib/asyncio/tasks.py | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py index 2d931040e57..7f7ee81403a 100644 --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -1110,7 +1110,7 @@ try: from _asyncio import (_register_task, _register_eager_task, _unregister_task, _unregister_eager_task, _enter_task, _leave_task, _swap_current_task, - _scheduled_tasks, _eager_tasks, _current_tasks, + _scheduled_tasks, _eager_tasks, current_task, all_tasks) except ImportError: pass |