[Python-Dev] Improve Python for embedding
theller at python.net
Mon Dec 22 14:28:24 EST 2003
I find the current situation when 'embedding' Python rather unsatisfying.
1. Careful preparation (hacking?) of environment variables is needed to
avoid that Py_Initialize() takes the default actions needed for the
standard Python interpreter (for example, to avoid the default sys.path).
2. A suggestion from /F on c.l.p was to change pythonw.exe so that
instead of hiding all output to stderr a console window would be opened
to show the tracebacks. This requires to construct an object with a
'write' method doing all this magic, and it must be done after the call
to Py_Initialize() and before PyRun_SimpleFile(). Now, looking at the
code of Py_Main(), it seems impossible without rewriting most of the
Possible improvements I currently can think of are:
- Provide a function like Py_InitializeEx(), which accepts parameters
specifying an initial sys.path, optimize flag, verbose flag, and so on.
- Split Py_Main() into 2 functions Py_Main_Prepare() and Py_Main_Run(),
or let Py_Main() accept a callback function which will be called jsut
after Py_Initialize() has been run.
I'm not ready to write a PEP, but if there are people sharing this
feeling I would suggest we create a wiki entry somewhere acting as a
temporary brainstorming area.
More information about the Python-Dev