mdefreitas at mdefreitas at
Fri Apr 28 22:14:22 CEST 2000

> Do you want to run several python scripts (and several ui.commands
> C code) concurently (how would you synchronize?) ?

I do not want to run concurrently, I just want to run in one thread of
execution, but recursively.

> Note that if all you want is to have C code that calls Python
> code that calls C code (through a module) that calls Python code
> without threads, PyRun_XXX functions are re-entrant.

Thanks! That's what I needed to know. I now modified (and simplified)
my code as follows:

void interp(char *script) {
   static int nest_level = 0;
   FILE *fd = fopen(script, "r");
   if (nest_level == 0) {
      PyRun_SimpleString("import ui\n"); // import my ui
   PyRun_SimpleFile(fd, script);
   if (nest_level == 0) Py_Finalize();

The only problem is that the nested script that is run "remembers" the
variable settings from it's caller. Is there a way to give each nested
python script a fresh, clean environment? The nested script should not
effect the environment of it's caller either. Is that what the global
and local dictionaries for the API function PyRun_File are for? If so,
is there any examples on their usage. The C/API doc isn't all that

Thanks for the help.

Sent via
Before you buy.

More information about the Python-list mailing list