En Tue, 10 Apr 2007 15:15:57 -0300, Yujo <[EMAIL PROTECTED]>  
escribió:

> In the following code of the finish() function, is there any way to
> get the exit code passed to sys.exit() ?
>
> def finish() :
>    RETURN_CODE_FROM_SYS_EXIT = ????    # how can I get it ?
>    if RETURN_CODE_FROM_SYS_EXIT = 0 :
>      # process ended OK
>    else :
>      # process ended with some error
>      # execute something
>
> atexit.register(finish)
>
> # this is my main program....
>
> ERR_CODE=3
> sys.exit(ERR_CODE)

Uhm, I think you can't, unfortunately (at least on 2.4; I don't have the  
2.5 sources at hand).
But you can instead wrap your main function with a try/except SystemExit:

def main():
   return 3

try:
   sys.exit(main())
except SystemExit, exitcode:
   finish(exitcode)

-- 
Gabriel Genellina

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to