using python interpreters per thread in C++ program

ganesh ganeshborse at gmail.com
Mon Sep 7 03:28:49 EDT 2009


On Sep 7, 2:04 pm, sturlamolden <sturlamol... at yahoo.no> wrote:
> I just showed you how...

Modified the thread function to use these APIs, but the call to
PyGILState_Ensure() is not returning at all.

void *callPyFunction(void * arg)
{
   // Method two to get function eval
   long thridx=(long)arg;
   printf("\n---->my num=%d, calling showstr pyfunction\n",thridx);
   char callpyf[] = "showstr(100)\n";
   PyGILState_STATE state = PyGILState_Ensure();
   printf("after PyGILState_Ensure\n");
   PyObject* pycall = PyRun_String(callpyf,Py_file_input,glb, loc);
   if(pycall == NULL || PyErr_Occurred()){
      printf("PyRun_String failed\n");
      PyErr_Print();
   } else
      printf("%d thread called showstr pyfunction ok\n",thridx);
   PyGILState_Release(state);
   pthread_exit(NULL);
}



More information about the Python-list mailing list