Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo
When a python script terminates due to an error (in Eclipse with PyDev Extensions), no variables are shown in the debug console, unlike standard IDEs like Wing and Komodo. Is there a way to make this happen?
Pydev currently does no exception-handling, however, you can add your own if you want to do so by changing the sys.__excepthook__
def myHook(*args, **kwargs):
sys._original_excepthook = sys.__excepthook__
sys.__excepthook__ = myHook
And then you can put a breakpoint in the 'sys._original_excepthook(*args, **kwargs)' line, so that whenever you have an unhandled exception it will stop there. An implementation of exception-handling in the debugger is planned, but it is still not implemented, so, you can add your own in this way.
I'm a python newb so I need more assistance with this. Where do I put the code you suggested, and how do I change the sys.__excepthook__ ? I don't understand unfortunately.
Will this give me the value of all by global and local variables when the program terminates with an exception, the way Wing and Komodo do? I rely heavily on this to work out what is going wrong with my programs.
You can put that anywhere, as long as you call it before getting into that exception.
And it should give you the globals and the locals in the stack-trace. It is not the same as stopping at that exact time, but it gives you the complete info on the stack.
Actually, I passed one thing wrong, you should change the sys.excepthook and not the sys.__excepthook__.
Below is a complete example showing how you'd get the locals in the stack-trace.
----------------- Example ------------
def m1(a = 10):
if __name__ == '__main__':
def myHook(type, value, traceback):
initial_ctx = traceback.tb_next
while initial_ctx.tb_next is not None:
initial_ctx = initial_ctx.tb_next
print 'locals on exception:', initial_ctx.tb_frame.f_locals
#now, call the original.
sys.__excepthook__(type, value, traceback)
sys.excepthook = myHook