GH-99205: Mark new interpreters and threads as non-static by brandtbucher · Pull Request #99268 · python/cpython
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I've pointed out two places where a comment would be appropriate. I'm approving the PR under the assumption you'll take care of those.
| memcpy(tstate, | ||
| &initial._main_interpreter._initial_thread, | ||
| sizeof(*tstate)); | ||
| tstate->_static = false; |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a note pointing to PyThreadState_INIT() and indicating that fields set there should be adjusted here as appropriate.
| // Set to _PyInterpreterState_INIT. | ||
| memcpy(interp, &initial._main_interpreter, | ||
| sizeof(*interp)); | ||
| interp->_static = false; |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pablogsal, leak tests didn't catch this because we use the "raw" domain to allocate PyThreadState and PyInterpreterState.
Oh interesting, can you confirm that changing the domain to memory makes the test fail?
You can't. :)
Fatal Python error: _PyMem_DebugCalloc: Python memory allocator called without holding the GIL
Python runtime state: preinitialized
See this comment:
| // We don't need to allocate a thread state for the main interpreter | |
| // (the common case), but doing it later for the other case revealed a | |
| // reentrancy problem (deadlock). So for now we always allocate before | |
| // taking the interpreters lock. See GH-96071. |
Thanks @brandtbucher for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request
…onGH-99268) (cherry picked from commit 283ab0e) Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
miss-islington added a commit that referenced this pull request
(cherry picked from commit 283ab0e) Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>