Repository navigation
gh-159041: Fix asyncio task tracking during thread state clear - #159319
mikegit123git wants to merge 3 commits into
Conversation
BHUVANSH855
left a comment
There was a problem hiding this comment.
Kindly sign CLA, so that maintainers can begin with review process.
BHUVANSH855
left a comment
There was a problem hiding this comment.
from the overview of changes, i just want to ask isn't this duplicate or overlaps with #159073
|
Thanks for pointing this out! I took a closer look at #159073, and you're right that both PRs address the same underlying issue. There are some differences in the implementation and regression tests. This PR focuses on thread-state cleanup and tests task tracking with an event loop running in another thread, while #159073 also handles interpreter shutdown and moves the task-list merge further toward the end of I'm happy to defer to the maintainers on whether to consolidate the changes. Thanks again! |
Fixes #159041
Summary
PyThreadState_Clear()currently merges the thread state's asyncio tasklist before the
Py_CLEAR()calls run finalizers. A finalizer can createan asyncio Task after the merge, leaving the Task linked to a thread state
that is subsequently freed.
Move the task-list merge after all finalizer-capable cleanup operations and
add a regression test for a Task created by a thread-state finalizer.
Tests
./python -m test test_asyncio.test_free_threading -j0(GIL build)./python -m test test_asyncio.test_free_threading -j0(free-threaded build)make patchcheckasyncioTaskcreated from a finalizer duringPyThreadState_Clear()registers into memory that is about to be freed (3.14 regression) #159041