Calling PyRun_SimpleString in a Child Process. [Was Forgetful Interpreter]

Bill Orcutt b_orcutt at
Sat Oct 18 06:07:05 CEST 2003

Thanks for your reply. I agree that PyRun_SimpleString should be
running in the same context-- its worked that way for me in the past--
The only thing that's different this time is fork() and that's what
I'm hoping someone will tell me how to deal with, since I'm stuck with
it this time.

I'm updating the subject line to something more descriptive.



Dave Kuhlman <dkuhlman at> wrote in message news:<bmprfj$pem2q$1 at>...
> Bill Orcutt wrote:
> > Having seen the number of lost souls asking questions about
> > embedding Python in the archives of this group, I hesitate to add
> > myself to their number, but I've hit a problem I can't quite get
> > my head around.
> > 
> > I have a simple C program that embeds a python interpreter to
> > execute python commands and return stdout, and to a point
> > everything works as intended. The problem that each command seems
> > to be executed in its own context and knows nothing of what's come
> > before. So if enter "print 2+2", I get back "4", but if I enter
> > "a=2+2" then enter "print a", I get back the error, "a is
> > undefined." My guess is that this has something to calling
> > PyRun_SimpleString inside of a child process, but I can't get much
> > further than this.
> Take a look at Python-2.3.2/Demo/embed/demo.c in the Python source
> code distribution for clues.  That program calls
> PyRun_SimpleString() several times with the same context.  If you
> do not switch interpreters (thread state, whatever) or
> re-initialize etc, then each call to PyRun_SimpleString() should
> have the same global variables etc.
> Why are you calling fork()?  Someone else will have to tell you
> the consequences of doing that.
> Dave
> [snip]

More information about the Python-list mailing list