Accessing run stack traces inside post_execute event handler

9 views
Skip to first unread message

Sudarshan Raghunathan

unread,
Jul 13, 2017, 4:05:05 PM7/13/17
to Project Jupyter
I am writing a "post_execute" event handler that looks something like this:
class MyEventHandler(object):
    def __init__(self, ip):
        self.shell = ip
       
    def post_execute(self):
        ec = self.shell.execution_count
        print("post execute: \nIn = %s\nOut = %s"%(self.shell.user_ns["In"][ec], self.shell.user_ns["Out"].get(ec, None)))

def load_ipython_extension(ip):
    eh = MyEventHandler(ip)
    ip.events.register("post_execute", eh.post_execute)

It works as expected when a cell runs successfully. However, when a cell fails with an exception, I could not find any way to get to the stack-trace that was generated. Is this possible somehow?

Thank you in advance!

Thomas Kluyver

unread,
Jul 14, 2017, 10:14:30 AM7/14/17
to Project Jupyter
I don't think it's currently possible. Do you want to file an issue on ipython/ipython to request it?

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/4937f1ad-2491-46e2-a9b7-aa2dcc2f2e54%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sudarshan Raghunathan

unread,
Jul 14, 2017, 11:53:41 AM7/14/17
to Project Jupyter

Thanks, filed an issue here: https://github.com/ipython/ipython/issues/10702

If you are able to provide me with some high-level guidance on how to implement this feature in run_cell, I will be more than happy to send a PR with the changes. For my own use-case, I don't need any changes to HistoryManager. In fact, I can just store an additional field parallel to last_execution_succeeded. However, I don't know if this is necessarily the best long-term option.

Please let me know and thanks again for your help.


On Friday, July 14, 2017 at 10:14:30 AM UTC-4, takowl wrote:
I don't think it's currently possible. Do you want to file an issue on ipython/ipython to request it?
On 13 July 2017 at 22:05, Sudarshan Raghunathan <rdar...@gmail.com> wrote:
I am writing a "post_execute" event handler that looks something like this:
class MyEventHandler(object):
    def __init__(self, ip):
        self.shell = ip
       
    def post_execute(self):
        ec = self.shell.execution_count
        print("post execute: \nIn = %s\nOut = %s"%(self.shell.user_ns["In"][ec], self.shell.user_ns["Out"].get(ec, None)))

def load_ipython_extension(ip):
    eh = MyEventHandler(ip)
    ip.events.register("post_execute", eh.post_execute)

It works as expected when a cell runs successfully. However, when a cell fails with an exception, I could not find any way to get to the stack-trace that was generated. Is this possible somehow?

Thank you in advance!

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages