python: Robust exception handling in callbacks.