Madhu <enom...@meer.net> added the comment:
* hai shi <rep...@bugs.python.org> <1629603770.32.0.682495978946.issue44...@roundup.psfhosted.org> Wrote on Sun, 22 Aug 2021 03:42:50 +0000 > hai shi <shihai1...@126.com> added the comment: > How about this one? > > if (!Py_IsInitialized()) { > return -1; > } [When this extension is loaded into a C program rather than a python script, then Python should be initialized here rather than quitting] > PyGILState_STATE state = PyGILState_Ensure(); > PyObject *module_handle = PyModule_New(module_name); > if (module_handle == 0) > { > fprintf(stderr,"PyModule_New(module_data_name=%s) failed\n", > module_name); > exit(1); > } > fprintf(stdout, "point is: %p\n", module_handle); > fprintf(stderr, "foo END\n"); > PyGILState_Release(state); Yes. Thanks. Calling PyGILState_Ensure and PyGILState_Release around the call to PyModule_New does avoid the segfault. It is a little tricky to do this in pam-python - because although there is one entrypoint into the extension (which can be wrapped within the calls to PyGILState_Ensure/Release), python is initialized within that entrypoint, but I think this can be solved another way. Thanks ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue44913> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com