Django Debug with a Threaded Pdb

By Rich Jones

Quick tip time!

Need to debug a Django website or API that you're building, but don't want to disrupt service for other developers or clients using your app? Well then, you're in luck, because this tip is for you!

If you don't know already, the python debugger, aka pdb, is the best tool ever. Just call pdb.set_trace() in your python apps and get an interactive shell wherever you want. Awesome!

However, that doesn't work well for debugging APIs, because it will cause your web server to either time out or return 400 or 500 errors because the debugger blocks the app from returning a real HTTP response.

However, with this little snippet, you can have your cake an eat it to! It will create a new thread with your debugger, and return an HTTP response to your client. Yay!

There you go! See ways to improve this script? Feel free to fork and comment below!

See More Posts About:


Posted by Rich Jones

LinkedIn Website