Extending embedded python of multiple interpreters



Hello All,

I have embedded python 2.5 in to my C application. As we need the
python scripts to run in multi threaded environment I have used
Py_NewInterpreter() and Py_EndInterpreter each time I execute a run
script function.
The code is as follows:
RunScript(char *pScriptName,char *pFuncName,...)
{
PyEval_AcquireLock()
threadState = Py_NewInterpreter();
PyThreadState_Swap(threadState);

/* Import the script module and run the fnc in that script module */
Pyobject *pModule = PyImport_Import(pScriptName);
PyObject *pFunc = PyObject_GetAttrString(pModule, pFuncName);
.....
/* End running the script and calling the script fnc */
Py_EndInterpreter(threadState);
PyEval_ReleaseLock();
}.

And my python initialise looks as :
pythonInit() {
Py_initialise();
PyEval_initThreads();//which enables multi thread support
}

Now I am extending the embedded python to expose my application
library API's to python using SWIG. I written one extension module and
from python i am setting the C structure member values which i
wrapped. I execute this python code using call to RunScript (above
function), it works fine for the first time, but from second time
onwards I get an error - Type Error : in method
<structurename_member>_set.
Hence my question is the same python code worked for first call, but
from 2nd call it is not working. Could any body help me where I am
making mistake.

Is extension modules does not work properly with multiple
interpreters? Does any body had this behaviour when worked with
extension modules and multiple interpreters creation for each thread.

Thanks in Advance for the help.

Vishnu
.



Relevant Pages

  • Exposing a COM interface to embedded scripts via PythonCOM
    ... I have a host process that exposes a COM object to embedded Python ... and want it to appear to the Python scripts as a "smart" COM ...
    (comp.lang.python)
  • Terminating a thread from the parent
    ... I have an app with embedded Python. ... Python scripts create their own ... threads and I need to terminate these threads at the point where the ...
    (comp.lang.python)
  • Re: Platform independent code?
    ... it seems that making a python script executable is platform dependant: ... Executable Python Scripts ... On BSD'ish Unix systems, Python scripts can be made directly executable, ... Are there any guidelines that gurantees that the python code will be ...
    (comp.lang.python)
  • Platform independent code?
    ... I have read that Python is a platform independent language. ... On BSD'ish Unix systems, Python scripts can be made directly executable, ... The script can be given an executable mode, or permission, using the chmod ...
    (comp.lang.python)
  • Python configuration question when python scripts are executed using Appweb as web server.
    ... I have installed python 2.6.2 in windows xp professional machine. ... to following windows folders: python root folder, ... I have configured IIS to execute python scripts. ...
    (comp.lang.python)