In my ipad 2, I find that almost whenever I task switch away from pythonista, when I come back I find that pythonista has restarted, presumably because ios killed it for memory.

It would be nice if I could write scripts or objects that can gracefully handle entering background, or terminated.
For instance, I have a bash-like history plugin for shellista, I'd like to save the history upon exit or entering background.

Does pythonista expose any of the underlying ios state change notifications? Or else, any way to register a finally that gets called before things quit, so I can save state info?