File tree 1 file changed +12
-4
lines changed
1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -149,19 +149,27 @@ inline void initialize_interpreter(bool init_signal_handlers = true,
149
149
PySys_SetArgvEx (argc, pysys_argv, static_cast <int >(add_program_dir_to_path));
150
150
#else
151
151
PyConfig config;
152
- PyConfig_InitPythonConfig (&config);
153
- config.safe_path = add_program_dir_to_path ? 0 : 1 ;
152
+ PyConfig_InitIsolatedConfig (&config);
154
153
config.install_signal_handlers = init_signal_handlers ? 1 : 0 ;
155
154
156
155
PyStatus status = PyConfig_SetBytesArgv (&config, argc, const_cast <char *const *>(argv));
157
156
if (PyStatus_Exception (status)) {
158
157
// A failure here indicates a character-encoding failure or the python
159
158
// interpreter out of memory. Give up.
160
159
PyConfig_Clear (&config);
161
- return ;
160
+ throw std::runtime_error ( " Failed to prepare CPython " ) ;
162
161
}
163
- Py_InitializeFromConfig (&config);
162
+ status = Py_InitializeFromConfig (&config);
164
163
PyConfig_Clear (&config);
164
+ if (PyStatus_Exception (status)) {
165
+ throw std::runtime_error (" Failed to init CPython" );
166
+ }
167
+ if (add_program_dir_to_path) {
168
+ PyRun_SimpleString (" import sys, os.path; "
169
+ " sys.path.insert(0, "
170
+ " os.path.abspath(os.path.dirname(sys.argv[0])) "
171
+ " if sys.argv and os.path.exists(sys.argv[0]) else '')" );
172
+ }
165
173
#endif
166
174
}
167
175
You can’t perform that action at this time.
0 commit comments