incompatible exit values between python 2.4 and 2.5



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
sys.exit(0)
but if I just want it to restart (to reread all modules) I can do
sys.exit(128)

With python 2.4, if pythonscript.py 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
try:
...
except ImportError, comment:
sys.exit(2)
except:
sys.exit(1)
but I still have to figure out how to print the stacktrace before
exiting with specific values.)

Regards
Anthon

.



Relevant Pages

  • [SOLVED] Re: os walk() and threads problems (os.walk are thread safe?)
    ... In main part i'm wait Queue to be empty and set EXIT after that, with this subdirectories in for loop does not process and program exit. ... # python test.py /usr ... I have a strange problem with os.walk and threads in python script. ...
    (comp.lang.python)
  • Re: subprocess returncode windows
    ... returncodes / exit status from python subprocess.call. ... but I can get the correct returncode from the shell every time. ... Unless asadmin.bat is playing tricks with %ERRORLEVEL% or something. ...
    (comp.lang.python)
  • Re: If/then style question
    ... When I started learning Python, I wrote a lot of methods that looked like ... exitCode = good1 ... you've got multiple exit points already. ... As PEP 20 says, "Readability counts". ...
    (comp.lang.python)
  • Re: EOF explanation
    ... programm -c python $* exit ... parameter in run_python script is taken as an input into script.py ...
    (comp.unix.shell)
  • Re: EOF explanation
    ... programm -c python $* exit ... parameter in run_python script is taken as an input into script.py ...
    (comp.unix.shell)