Post execute event handlers do not have access to exceptions for failed cells #10702

Open
drdarshan opened this Issue Jul 14, 2017 · 1 comment

Comments

Projects
None yet
2 participants

If you write a post-execute event handler:

class MyEventHandler(object):
    def __init__(self, ip):
        self.shell = ip
       
    def post_execute(self):
        ec = self.shell.execution_count
        input = self.shell.user_ns["In"][ec]
        output = self.shell.user_ns["Out"].get(ec, None)
        succeeded = self.shell.last_execution_succeeded
        ## stack_trace = ???
        
def load_ipython_extension(ip):
    eh = MyEventHandler(ip)
    ip.events.register("post_execute", eh.post_execute)

The handler can get access to the cell that was just run and the outputs if the run succeeded. However, if the run failed, there is no way for the handler to get hold of the stack trace that was produced. It would be ideal if the handler was passed in the result of run_cell or if there was a way to get hold of the result from the history manager.

Owner

takluyver commented Jul 15, 2017

I think the easiest way to do this would be to attach the ExecutionResult object to shell before we call the hooks. Changing what's passed to a callback is tricky, unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment