views:

143

answers:

1

I am looking for some way in django's development server that will make the server to stop at any uncaught exception automatically, as it is done with pdb mode in ipython console.

I know to put import pdb; pdb.set_trace() lines into the code to make application stop. But this doesn't help me, because the line where the exception is thrown is being called too many times. So I can't find out the exact conditions to define a conditional break point.

Is this possible?

Thank you...

+2  A: 

You can set sys.excepthook to a function that does import pdb; pdb.pm(), as per this recipe.

Alex Martelli
Somehow I can't override sys.excepthook:http://stackoverflow.com/questions/1261668/cannot-override-sys-excepthookIs this normal?
Mert Nuhoglu
@Mert, as I explained answering that question, ipython (which in that question you mention you're using) is different. So either run `ipython -pdb`, or plain `python` which this excepthook override.
Alex Martelli
@Alex, Thanks for the explanation.I have one more question:I can catch any uncaught exception through overriding sys.excepthook when I run a python script. That's good.But this recipe doesn't work when I run django server. The exception is caught and logged by django. Is it possible to make pdb catch the exception?
Mert Nuhoglu
Ok, I got it. Django's debug module catches and logs any uncaught exception. pdb doesn't catch the exception because the recipe makes pdb to catch any uncaught exception, not caught exceptions.
Mert Nuhoglu
@Mert, yep. There are actually ways to hook up a debugger, esp. if you're running django on WSGI, see http://code.google.com/p/modwsgi/wiki/DebuggingTechniques -- but setting sys.excepthook is still all about uncaught exceptions.
Alex Martelli
I have just found Werkzeug tool. That is very useful for debugging where an exception occurs. http://ericholscher.com/blog/2008/aug/28/screencast-debugging-django-error-page/
Mert Nuhoglu