atexit handlers - getting the return code

Giampaolo Rodolà g.rodola at gmail.com
Tue Sep 27 08:55:17 EDT 2011


You mean the registered function return value or the process return code?
In the first case you can do something such as:

import atexit

@atexit.register
def cleanup():
     def actual_function():
           ...
           return something
     ret = actual_function()
     # do something with ret

In the latter case you can use sys.exit(code).

--- Giampaolo
http://code.google.com/p/pyftpdlib/
http://code.google.com/p/psutil/

2011/9/27 Mike Hull <mikehulluk at googlemail.com>:
> Hi,
> I work in neuroscience modelling and use python for lots of my work.
> One problem I have is management of scripts and results. To that end,
> I have
> written code that make its easier to keep track of scripts, to see
> which ones
> have run, or need to be rerun, to see output errors and generally
> organise running of scripts better.
>
> The way i have implemented it is that I register a function to the
> atexit module,
> which takes care of recording information about the script run; such
> as whether an
> exception was raised and not caught, and how long it took to run and
> the
> stdout/stderr streams; which can then be uploaded into a database.
>
> One thing I am struggling to get though is the 'return code' that the
> is going to be returned after my
> atexit handlers have finished. Could anyone tell me how it get at
> this!?
>
>
> Thanks
>
>
> Mike
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list