You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
An interpreter can start running during _interpreters.destroy #127041
Now that gh-126914 is out of the way, we can try and deal with some of the other issues related to multithreading and subinterpreters that couldn't get dealt with before. Namely, the is_running_main inside _interpreters.destroy doesn't account for the fact that the interpreter could start running again by another thread after that check has already passed.
I think the simplest fix would be to just disallow a subinterpreter from ever set "running main" again after that check has finished. I implemented this already in the (closed) gh-126696, but I'd like to try and refactor that a bit before just copying things over to a new PR.
Hello @ZeroIntensity and @ericsnowcurrently, I'd like to work on it (If neither of you are working on it, and if it's allowed to work on by newcomers). I have reproduced this on Windows 11, Version: 23H2 as well.
I think this is what's happening in brief?
Thread 1 (destroy): check !is_running_main ─────────────> teardown (CRASH)
Thread 2 (run_str): enter & run ───┘
I want to explore something along the following lines:
We guard threads.main and use destroying flag via a PyMutex in struct pythreads.
I'd appreciate your feedback and guidance on this approach before proceeding further.
Disclosure: I have utilized LLM agents to understand the issue better, and the flow of the program, along with understanding the changes made in earlier PR (in biref).
Activity
utam-1 commentedon Nov 12, 2026
Hello @ZeroIntensity and @ericsnowcurrently, I'd like to work on it (If neither of you are working on it, and if it's allowed to work on by newcomers). I have reproduced this on Windows 11, Version: 23H2 as well.
I think this is what's happening in brief?
I want to explore something along the following lines:
We guard
threads.mainand use destroying flag via aPyMutexinstruct pythreads.I'd appreciate your feedback and guidance on this approach before proceeding further.
Disclosure: I have utilized LLM agents to understand the issue better, and the flow of the program, along with understanding the changes made in earlier PR (in biref).
ZeroIntensity commentedon Nov 12, 2026
You can take a stab at this. I would recommend looking into the PEP 788 APIs for fixing this rather than another locking layer.