Launch an IPython shell on exception

前端 未结 10 2375
长情又很酷
长情又很酷 2020-12-04 09:30

Is there a way to launch an IPython shell or prompt when my program runs a line that raises an exception?

I\'m mostly interested in the context, variables, in the sc

10条回答
  •  臣服心动
    2020-12-04 09:55

    You can do something like the following:

    import sys
    from IPython.Shell import IPShellEmbed
    ipshell = IPShellEmbed()
    
    def excepthook(type, value, traceback):
        ipshell()
    
    sys.excepthook = excepthook
    

    See sys.excepthook and Embedding IPython.

提交回复
热议问题