Description
The following functions needs to be made thread safe and atomic for free-threading for both pure python and C implementation:
-
asyncio._enter_task
-
asyncio._leave_task
-
asyncio._register_task
-
asyncio._unregister_task
-
asyncio._swap_current_task
-
asyncio.current_task
-
asyncio.all_tasks
Note that some of these were made thread safe in C impl #120974
The following classes needs to be thread safe for free-threading in C implementation:
-
asyncio.Task
-
asyncio.Future
Both of these classes are documented to be not thread safe but currently calling methods on these classes from multiple threads can crash the interpreter. The pure python implementation cannot crash the interpreter when called from multiple threads so changes are only needed for C implementation. Before making these thread safe in C I would gather some numbers for how much a difference the C implementation makes in free-threading and if it isn't much we can just disable the C extension for free-threading.
cc @colesbury
Linked PRs
- gh-128002: fix many thread safety issues in asyncio #128147
- gh-128002: use internal llist implementation for asyncio tasks #128256
- gh-128002: add more thread safety tests for asyncio #128480
- gh-128002: fix
asyncio.all_tasks
against concurrent deallocations of tasks #128541 - gh-128002: use per threads tasks linked list in asyncio #128869
- gh-128002: use
_PyObject_SetMaybeWeakref
when creating tasks in asyncio #128885 - gh-128002: fix
test_all_tasks_different_thread
in asyncio #129267 - gh-128002: simplify all_tasks to use
PyList_Extend
instead of manual iteration #129942 - gh-128002: add fast path for native tasks in
asyncio.all_tasks
#129943 - gh-128002: optimistically remove tasks from linked list when finished #129995
- gh-128002: use efficient linked list impl for eager tasks in asyncio #130518
- gh-128002: add test_asyncio.test_free_threading to tsan tests #131106
- gh-128002: fix tsan race in closing socket in test_ssl #131397
- gh-128002: fix tsan race in closing socket in test_sslproto #131399
- gh-128002: run all asyncio tests with tsan CI #131797
- [3.14] gh-128002: add what's new docs for
asyncio
(GH-134324) #134362 - gh-128002: add what's new docs for asyncio #134324
Metadata
Metadata
Assignees
Projects
Status