-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Malformed PyImport_Inittab after re-initialization #88607
Comments
Hi all, I observed misbehavior trying to embed the Python interpreter into a C app. Steps to reproduce:
Observed behavior:
The script is executed at first iteration, but re-initialization fails with an error:
"
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 1187, in _install_external_importers
ModuleNotFoundError: No module named 'posix' Error: external importer setup failed Head of modules list at fist run: An issue discovered on: Issue still exists on the latest main and on the rc 3.10 Best regards, |
inittab-bug.c uses the Python C API in 3 threads:
Problem: the thread B (run_proc) doesn't hold the GIL and so I get a fatal error with Python built in debug mode: $ gcc inittab-bug.c -ggdb -pthread -lpython3.11d -L. -I. -I Include/
$ PYTHONPATH=$PWD/Lib LD_LIBRARY_PATH=$PWD ./a.out
------ Modules: #0 'posix' Thread 0x00007f61ce5c1640 (most recent call first): If I remove the thread B (comment the comment), I get a similar error in the main thread which calls Py_FinalizeEx(). Please fix your usage of the GIL. For example, you can try to use:
Usually, Python initialization and Python finalization is done in the same thread, but another thread can use the Python C API if it acquires the GIL using PyGILState_Ensure(). |
Hi vstinner, I apologize for the inaccurate code sample. Steps to reproduce:
Observed behavior: gdb) r
Starting program: /home/kheb/proj/tmp/pyc/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Run Python Script
>>> This is the python script
Python Script completed (0) Program received signal SIGSEGV, Segmentation fault. I hope this example helps. Best regards, |
Thanks for inittab-bug_no-threads.c reproducer. I managed to reproduce the issue and I wrote PR 26767 to fix with a regression test. |
Thanks kryheb for your bug report, reproducer and your fix! The bug should now be fixed in 3.9, 3.10 and main branches. |
Thanks vstinner for your help and for taking care of this case! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: