mirror of
https://github.com/python/cpython.git
synced 2026-06-22 19:12:50 -04:00
gh-151253: Dump the Python path configuration on _PyCodec_InitRegistry() failure (#151250)
If "import encodings" fails at Python startup, dump the Python path configuration to help users debugging their configuration. The encodings module is the first module imported during Python startup.
This commit is contained in:
@@ -11,6 +11,7 @@ Copyright (c) Corporation for National Research Initiatives.
|
||||
#include "Python.h"
|
||||
#include "pycore_call.h" // _PyObject_CallNoArgs()
|
||||
#include "pycore_codecs.h" // export _PyCodec_LookupTextEncoding()
|
||||
#include "pycore_initconfig.h" // _Py_DumpPathConfig()
|
||||
#include "pycore_interp.h" // PyInterpreterState.codec_search_path
|
||||
#include "pycore_pyerrors.h" // _PyErr_FormatNote()
|
||||
#include "pycore_pystate.h" // _PyInterpreterState_GET()
|
||||
@@ -1686,6 +1687,8 @@ _PyCodec_InitRegistry(PyInterpreterState *interp)
|
||||
// search functions, so this is done after everything else is initialized.
|
||||
PyObject *mod = PyImport_ImportModule("encodings");
|
||||
if (mod == NULL) {
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
_Py_DumpPathConfig(tstate);
|
||||
return PyStatus_Error("Failed to import encodings module");
|
||||
}
|
||||
Py_DECREF(mod);
|
||||
|
||||
Reference in New Issue
Block a user