Skip to content

gh-149816: fix concurrent kwargs growth in _thread.start_new_thread#150168

Open
YvesDup wants to merge 3 commits into
python:mainfrom
YvesDup:62-Concurrent-kwargs-growth-ft
Open

gh-149816: fix concurrent kwargs growth in _thread.start_new_thread#150168
YvesDup wants to merge 3 commits into
python:mainfrom
YvesDup:62-Concurrent-kwargs-growth-ft

Conversation

@YvesDup
Copy link
Copy Markdown
Contributor

@YvesDup YvesDup commented May 20, 2026

IMO, to fix this issue, there are 2 options:

  1. in the PyStack_UnpackDict function located in /Objects/call.c, wraps the PyDict_Next loop in a critical section to prevent concurrent mutations of the same dict.

  2. in the /Modules/_threadmodule.c, duplicate the kwargs dict in the thread_run function, before calling the thread's main function. So that the thread will be working with a private copy of the kwargs dict.

In the option 1, the PyStack_UnpackDict function is called many times, from PyObject_VectorcallDict via _PyObject_VectorcallDictTstate, PyVectorcall_Call via _PyVectorcall_Call or _PyEvalFramePushAndInit_Ex. This change is not necessary for these functions and, furthermore, would have an impact on their performance.

I am in favor of option 2, as it has a more limited scope and shouldn't have a performance impact
on regular builds, while still fixing the issue for FT builds.

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.

1 participant