1

I am trying to produce information upon exit of a python program. I am thinking that using an atexit function would permit me to create a generalized termination procedure - if the exit is a zero condition code, then I would print out one thing, non zero then something else. Seems to me this would be accomplished with a simple conditional on the exit code, but I can't seem to find any reference on how to access the value of the exit code...? Does anyone know how to access the exit code in an atexit function? Or perhaps there is a more pythonic way to do this? Thanks very much, phil

4
  • atexit only registers a function to run upon termination, which must be defined by you. The output of atexit will be determined by the custom function you include in atexit. Commented Aug 13, 2018 at 13:13
  • Possible duplicate of How to find exit code or reason when atexit callback is called in Python? Commented Aug 13, 2018 at 13:14
  • It is a possible duplicate, yet my goodness, all that code to access a value that should be available somewhere? I was looking at sys.exc_info()[1] but it seems to return 'None' Commented Aug 13, 2018 at 13:27
  • This works: def xfun(): print("{0} Ending {1} RC={2}".format(aud_dt(), file ,sys.exc_info()[1])) Commented Aug 14, 2018 at 19:05

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.