MORE INFO

Cedric Adjih adjih at crepuscule.com
Fri Apr 28 11:23:18 EDT 2000


mdefreitas at sikorsky.com wrote:
> By the way... I finally tested the code I wrote and it evidently is
> incorrect. It works fine on the first nest level, but my application
> aborts on the second nest level.

> The error message is:
> Fatal Python Error: PyThreadState_Get: no current thread

> OK... I'm lost. Any ideas? Anybody? Buelher?

  Hmm... I can't answer because I'm not a Python threading expert,
but I didn't understand your thread model: do you want to run
several python scripts (and several ui.commands C code)
concurently (how would you synchronize?) ?
  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
(these functions are even called reentrantly by the Python interpreter
itself for the "eval", "execfile" functions, check Python/bltinmodule.c).

If you want to pass arguments to your script, you could use the
other PyRun_File function with a dictionnary with args for locals, see
  http://www.python.org/doc/current/api/veryhigh.html
(the 'int start' should be Py_file_input)


Note that a more flexible way to implement a 'python'
command is:
- to initialize the python interpreter
- to load a fixed module ("pythonexec.py" for instance)
(PyImport_ImportModule)
- to call a function with a given name from this module
(PyModule_GetDict + PyDict_GetItemString + PyObject_CallFunction 
should do, maybe there is something shorter), with as
argument the whole command string.

I.e. do the equivalent of: 
import pythonexec
pythonexec.doEval(<the python command string>)

Then you can start with 'pythonexec.py' being:
import string
def doEval(cmdLine):
  arg=string.split(cmdLine)
  execfile(arg[0],{'argv': cmdLine[1:]})


And then later change doEval to do more elaborate
parsing (for instance if an argument begins with '$',
first eval the argument as an ui command, or if
the filename is 'eval' just evaluate the string,
or don't do execfile, but an import+apply, ...)

-- Cedric




More information about the Python-list mailing list