incompatible exit values between python 2.4 and 2.5

A

Anthon

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
 
D

Diez B. Roggisch

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.)

For the latter, take a look at

sys.exc_info()


Diez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top