I'm writing an application that has an embedded Python interpreter, but can also run script files from within the application.
What I want to archive is to have a way to reset the interpreter or that it can execute a file/statement without affecting the global environment so you can run a script, edit the file and run the script again without finalizing python in between (or reset my interpreter).
I've tried to create a new interpreter but then sometimes it hangs the whole application (deadlock). Here is a small demo to see the problem.
Py_Initialize();
PyThreadState* pGlobalThreadState = PyThreadState_Get();
PyThreadState* pInterpreterThreadState = Py_NewInterpreter();
PyThreadState_Swap(pInterpreterThreadState);
PyRun_SimpleString("import PySide"); // Importing PySide deadlocks
Py_EndInterpreter(pInterpreterThreadState);
PyThreadState_Swap(pGlobalThreadState);
If I save GIL states it sometimes works, but that isn't supported together with Py_NewInterpreter according to documentation.
Using Python 3.4.
Is there any other solution to run commands in a separate environment or to fix the deadlock?