Hi,
I am trying to create multiple python interpreter using Py_NewInterpreter() function in C++ thread. When i run the code sometime it works but sometime it just hanged .Looks like some threads are waiting to acquire the lock which has not been released and thats why a deadlock.

#
void *threadFunc(void *arg)
{
PyThreadState* tState;
PyEval_AcquireLock();
tState = Py_NewInterpreter();
PyThreadState_Swap(tState);
PyRun_SimpleString("print \"hello\"");
PyErr_Clear();
Py_EndInterpreter(tState);
PyThreadState_Swap(NULL);
PyEval_ReleaseLock();
pthread_exit(NULL);
}
int main()
{
pthread_t p;
int i;
Py_InitializeEx(1);
PyEval_InitThreads();
mainThreadState = PyThreadState_Get();
PyEval_ReleaseLock();
for(i=0; i<10; i++)
{
pthread_create(&p, NULL, threadFunc, (void *)argv);
}
pthread_join(p, NULL);
PyEval_RestoreThread(mainThreadState);
Py_Finalize();
pthread_exit(NULL);
return 0;
}
#