Message355186
Extract of test2.C:
---
// in main thread
Py_Initialize();
PyEval_InitThreads();
PyEval_SaveThread();
// creating a new sub-interpreter, in my real app, this would be created
// in a sub-thread.
PyInterpreterState* const mainInterpreterState = PyInterpreterState_New();
PyThreadState* const taskState = PyThreadState_New(mainInterpreterState);
PyEval_AcquireThread(taskState);
PyThreadState * const sub_interp = Py_NewInterpreter();
PyThreadState_Swap( taskState );
PyEval_ReleaseThread( taskState );
---
IMO this code is not supported. It creates 3 interpreters:
* Py_Initialize(): good
* PyInterpreterState_New(): partially initialized
* Py_NewInterpreter(): created from the partially initialized interpreter
IMHO PyInterpreterState_New() should never be used outside Python internals. Only Py_NewInterpreter() should be used.
At least, this code now fails since PyInterpreterState_New() configuration (interp->config) is empty/uninitizalized, and so _PySys_InitMain() fails.
Moreover, the example uses PyGILState C API which isn't compatible with subinterpreters yet :-( |
|
Date |
User |
Action |
Args |
2019-10-23 00:06:49 | vstinner | set | recipients:
+ vstinner, pitrou, martin.panter, zach.ware, skydoom |
2019-10-23 00:06:49 | vstinner | set | messageid: <1571789209.38.0.860972979256.issue26693@roundup.psfhosted.org> |
2019-10-23 00:06:49 | vstinner | link | issue26693 messages |
2019-10-23 00:06:49 | vstinner | create | |
|