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

  • `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`. – vielkind Aug 13 '18 at 13:13
  • Possible duplicate of [How to find exit code or reason when atexit callback is called in Python?](https://stackoverflow.com/questions/9741351/how-to-find-exit-code-or-reason-when-atexit-callback-is-called-in-python) – cdarke Aug 13 '18 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' – Philippe Godfrin Aug 13 '18 at 13:27
  • This works: def xfun(): print("{0} Ending {1} RC={2}".format(aud_dt(), __file__ ,sys.exc_info()[1])) – Philippe Godfrin Aug 14 '18 at 19:05

0 Answers0