incompatible exit values between python 2.4 and 2.5

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anthon

    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

  • Diez B. Roggisch

    #2
    Re: incompatible exit values between python 2.4 and 2.5

    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

    Comment

    • John Machin

      #3
      Re: incompatible exit values between python 2.4 and 2.5


      Diez B. Roggisch wrote:
      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()
      >
      or perhaps the traceback module ...

      Cheers,
      John

      Comment

      Working...