Embedded python

A

Anand K Rayudu

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
 
M

Marek =?iso-8859-2?Q?Baczy=F1ski?=

Dnia Mon, 05 Jul 2004 20:17:10 +0530, Anand K Rayudu napisa³(a):
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.

It's hard to tell what's wrong; you may want to ask your question on
From what I see you don't do a lot of necessary error
checking (basically every result should be checked for an exception, even if
you know there can't be any), but that likely isn't everything. Missing
INCREFs/DECREFs may cause trouble, etc.
 
M

Marek =?iso-8859-2?Q?Baczy=F1ski?=

Dnia Mon, 05 Jul 2004 20:17:10 +0530, Anand K Rayudu napisa³(a):
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.

It's hard to tell what's wrong. From what I see you don't do a lot of necessary error
checking (basically every result should be checked for an exception, even if
you know there can't be any), but that likely isn't everything. Missing
INCREFs/DECREFs may cause trouble, etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top