[Python-Dev] py3k, bad sys.path and abort()

Mark Hammond skippy.hammond at gmail.com
Sun Jan 4 07:47:31 CET 2009


I've recently noticed that in py3k, the lack of a suitable sys.path will 
cause Py_FatalError() to be called, which immediately terminates the 
entire application.

On Windows, it is fairly easy for this to happen for developers or 
anyone who hasn't run the official Python installation; just have Python 
used in a 'service', web server, COM object or anything else which loads 
python3x.dll from the system32 etc directory, and neglect to have added 
the PYTHONPATH entry in the registry or global environment.  As a result 
Python can't sniff a good default sys.path, fails to import encodings, 
then winds up calling Py_FatalError("Py_Initialize: can't initialize sys 
standard streams");

I realize this is something of an edge-case, but having abort() called 
on the application in this case is somewhat harsh and difficult to 
diagnose.  In Python 2.x, you end up with a fairly crippled Python 
environment, but it functions well enough to offer clues that your 
sys.path isn't setup.

Would it be practical and desirable to handle this situation more 
gracefully, possibly just leaving sys.std* set to None and letting 
whatever exceptions then occur happen as normal without terminating the 
process?  Given it is an edge-case, I thought I'd open it here for 
discussion before putting work into a patch or opening a bug.

Thanks,

Mark


More information about the Python-Dev mailing list