incompatible exit values between python 2.4 and 2.5

Anthon Anthon.van.der.Neut at
Mon Sep 18 10:21:17 CEST 2006

I have a small C program that restarts a python based server
application if the exit value of the
   system("python -m pythonscript arg1 arg2 ...")
is greater than 127 (using WEXITSTATUS on the result of system(..))
If the server really needs to stop I exit with
but if I just want it to restart (to reread all modules) I can do

With python 2.4, if could not be found, the exit value
would be 2 and if there was some syntax error, or other exception
raised, the exit value would be 1.

While trying this out with Python 2.5 I found that the exit value on
error is always 255, so I have to change my script (not a big deal).
However two questions came up while finding out what was
the difference:

1) is this change of behaviour documented somewhere and did I miss
that, or has this not been documented (yet)
2) Is there a build-in way to set the exit value for Python in case an
exception is raised that is uncaught and causes python to terminate? (I
have now implemented something using
   except ImportError, comment:
but I still have to figure out how to print the stacktrace before
exiting with specific values.)


More information about the Python-list mailing list