python has atexit module to register functions to run prior to closing of the interpreter. This question nicely why atexit is not called.
I'm wondering if there is an alternative for ipython
to register a function prior to exiting something which has been run with %run <name>
? Ideally I would like to create a decorator which works registers in either
module depending on the interpreter.