A fail-safe for long-running python scripts
<p>This may be the dumbest question ever, but I'd like to know if there's a way to write a wrapper around a function (preferably a decorator) so that you can catch the internal state of the local variables in the event that an exception was raised in that function. It would catch the locals as they're created, pickle them, and then dispose of them if no exceptions were raised, or write them to file if any exceptions were found.</p>

<p>Is this too fanciful, or has anyone fooled around with something like this?</p>
