Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Using pdb with Flask application

Tags:

python

flask

pdb

I'm using Flask 0.9 with Python 2.7.1 within a virtualenv, and starting my app with foreman start

In other apps I've built when I add the following line to my app:

import pdb; pdb.set_trace()

then reload the browser window, my terminal window displays the pdb interactive debugger:

(pdb)

However in my app when I add those lines nothing happens. The browser window hangs and shows a constant state of loading yet nothing shows in the console.

Is there some magic that needs to happen?

like image 782
commadelimited Avatar asked Mar 31 '13 04:03

commadelimited


1 Answers

This is because you're using Foreman, which captures the standard output.

To debug your app with pdb, you'll need to "manually" run it, using python app.py or whatever you use.

Alternatively, you can use WinPDB (which, despite the name, has nothing to do with the operating system), which will let you remotely debug a Python process. You can even use it when the program is running on another server.

like image 109
David Wolever Avatar answered Oct 30 '22 13:10

David Wolever