[python-win32] Fatal Python error:PyThreadState_Get: No
currentThread
Mark Hammond
mhammond at skippinet.com.au
Sat May 15 07:21:50 EDT 2004
> // The following my COM object code to get the python callback.
>
> SetCallBack(BSTR module_name, BSTR callbk_name){
You need to add:
PyGILState_STATE state = PyGILState_Ensure();
> PyObject *mod = PyImport_AddModule(module_name); // The Fatal
> error is generated while doing this
>
>
> // Actually this calls PyImport_GetModuleDict();
>
>
> // This is the function which is failing.
> if(!mod) return S_OK;
>
> m_pPyCallbk=PyObject_GetAttrString(mod,callbk_name);
and at *every* single exit point (including the one above - 'goto error;' is
what I tend to use)
PyGILState_Release(state);
> return S_OK;
>
> }
> Can some one please suggest how to solve this.
> or is there a better way to pass python function to COM objects.
I'm not sure why you are using COM to pass Python stuff around - if you are
already assuming Python, then just use the Python API directly without the
COM overhead - ie, in your example, "SetCallBack" could just be a method on
an object in a regular Python extension. You may have a good reason - in
which case, it seems fine!
Mark
More information about the Python-win32
mailing list