-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segfault when trying to use PyRun_SimpleString() with some imports #124160
Comments
Otherwise it'll always return NULL if tstate != main_tstate due to _Py_IsMainInterpreter() check inside it.
I wasn't able to get an embedded interpreter working with Though, I did try this directly on CPython (via (@encukou, for now, this needs |
Just fyi, you need both brotli and requests, it won't die w/o both of them installed. Unless importing brotl alone can trigger this crash too, but I haven't tried that myself. |
It does, I updated the op. |
Oh, I only tried this with With that being said, it doesn't look like I wonder if something else is going wrong here, because you'll lose some errors by omitting |
This happens with some other modules too, e.g.
so I assumed this is a regression in CPython and that module maintainers shouldn't have to apply workarounds to fix 3.13 support.
|
Well that's not good :( Are there any modules in the stdlib that this occurs with? (That makes it much easier to track down, so you don't have to deal with virtual environments when testing.) Also, I'm assuming that the |
No idea about stdlib also it doesn't happen w/o PyThreadState_Swap(). BTW I uploaded a simple PR that fixes it, if you didn't notice it yet ^^ |
I saw, I just don't know whether it's the correct fix because I can't reproduce it yet.
Good to know, that means this is a subinterpreter problem. As far as I can see, |
Wrote a quick script to traverse the whole support std modules and there's a few hits that make it crash import sys
import importlib
for mod in sys.stdlib_module_names:
try:
print(mod)
importlib.import_module(mod)
except:
pass so far Since the list isn't sorted you may be able to hit a few more entries I missed :) Update to handle exceptions since some modules are listed but not loadable (like turtle) |
Thanks! I don't have a chance to try and reproduce this at the moment, but I think the problem is with using a module state with single-phase init under a subinterpreter. The fix by @luk1337 makes sense to me. |
thx, I updated OP with readline instead of brotli |
FWIW, the fix in gh-124164 is correct. It should have been using |
Otherwise it'll always return NULL if tstate != main_tstate due to _Py_IsMainInterpreter() check inside it. Also, add a regression test that makes sure that `readline` is importable in case that triggered the crash before.
Otherwise it'll always return NULL if tstate != main_tstate due to _Py_IsMainInterpreter() check inside it. Also, add a regression test that makes sure that `readline` is importable in case that triggered the crash before.
Otherwise it'll always return NULL if tstate != main_tstate due to _Py_IsMainInterpreter() check inside it. Also, add a regression test that makes sure that `readline` is importable in case that triggered the crash before.
Alas, a reproducer that does not require C code: import _interpreters
interp = _interpreters.create()
_interpreters.run_string(interp, "import readline") |
…n() (pythonGH-124164) (cherry picked from commit 7331d0f) Co-authored-by: luk1337 <[email protected]>
…xtension() (cherry picked from commit 7331d0f)
Crash report
What happened?
I hit the segfault when doing the following thing:
The same code doesn't crash on 3.12.
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.13.0rc2 (main, Sep 7 2024, 00:00:00) [GCC 14.2.1 20240801 (Red Hat 14.2.1-1)]
Linked PRs
The text was updated successfully, but these errors were encountered: