Embedded python

Anand K Rayudu anand.k.rayudu at esi-group.com
Mon Jul 5 16:47:10 CEST 2004


Hi all,

I have embedded python and want to execute python scripts from my 
application. I need to call the execution of python repeatedly, and some 
times same script again & again.
I am facing some problems , especially if i try to execute the same 
script again.
Some times  in loading my module. Even it looks like for loops are not 
working, if i replace them with 'while' it worked.
This is on windows system with python 2.3.3 , I have win32 extensions also.

Can some body please review following and suggest if any thing is wrong 
here. Or suggest better way of doing it.


//  Python will be initialized only once in life time
if(!Py_IsInitialized())
      Py_Initialize();
// create new iterpeter

 PyEval_AcquireLock();
  tstate = Py_NewInterpreter();

    sprintf(exec_command, "a=%s(100)",script_name);
    PyObject *result = PyRun_String(exec_command,Py_file_input,d,d) ;
    sprintf(exec_command, "a.%s()","Ecexute");
    PyRun_String(exec_command,Py_file_input,d,d) ;

// close current interpeter thread
if(tstate){
    Py_EndInterpreter(tstate);
     PyEval_ReleaseLock();
       tstate = NULL;
    }


// My python coce looks like this


PythonScript.py
class PythonScript:
   def __init__(self,block):
        self.a = block
   def Execute(self):
        import myModule
        myModule.Api1()

       # very complex logic associated with my APIs here.

Thanks In advance.

Anand






More information about the Python-list mailing list