Can I get the exit code "n" passed to sys.exit(n) ?

Y

Yujo

Hello everybody,

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)


Regards,

Yujo
 
K

kyosohma

Hello everybody,

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)

Regards,

Yujo

I'm not sure if this will help or not, but this article is pretty
enlightening and is written by a well-known Pythonista:

http://www.artima.com/weblogs/viewpost.jsp?thread=4829

Here is another older post with helpful information:
http://www.daniweb.com/techtalkforums/thread31226.html

And here's a hack that might work: http://www.daniweb.com/techtalkforums/thread31166.html

Mike
 
G

Gabriel Genellina

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)
 

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

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top