PyRun_File crash my application

Michael P. Reilly arcege at shore.net
Mon Dec 6 19:10:17 EST 1999


Bing Chen <BC at prism.co.nz> wrote:
: Hi, all
: I try to embed PyRun_File in my application. It crashed. Anybody know what's
: happen. How can I run a file in Python interpreter? My code as follows:
:   FILE * fp = fopen( py_token, "r" ); #py_token is a file name
:   PyObject *module = PyImport_AddModule("__main__");
:   PyObject *dict   = PyModule_GetDict(module);
:  PyRun_File( fp, py_token,Py_file_input, dict, dict );

If you didn't initialize the Python system then you could get an
assertion (Fatal Python error: PyThreadState_Get: no current thread).

Insert a call to "Py_Initialize();" before you call any Python/C API
functions.

(Also, I assume the "#..." comment is not part of your C code ;)

  -Arcege

http://www.python.org/doc/current/api/initialization.html





More information about the Python-list mailing list