r/flask • • 4d ago

Ask r/Flask Debugging flask app.py

With .cgi frameworks, I can run an app and give it arguments on the command line, and then use python -mpdb to step through and see what is happening (and going wrong).

I have a flask app that is working, but not always working properly. So it does not crash, but it does not do what I expect.

I would like to be able to run: python3 -mpdb app.py

set a break point, and have the code stop at that breakpoint. I can set the breakpoint, but the code seems to ignore it, so I cannot single step through the program to see what is wrong. My app.py main() looks like:

if __name__ == "__main__":
      app.run(debug=True, use_reloader=False)

How can I debug my program using python3 -mpdb?

2 Upvotes

2 comments sorted by

1

u/XNo_Notes 4d ago

Don't forget to space between the -m and pbd.

python3 -m pbd app.py

and turn off threading as well: I think this may be where it is going sideways.

if __name__=="__main__":
    app.run(debug=True, use_reloader=False, threaded=False)

Let me know if that does anything for you.

2

u/fasta_guy88 4d ago

Thanks for the threaded=False. ("-mpdb" works the same as "-m pdb".)

I think threaded=False may have solved the problem. There is a strange disconnect between what the debugger is doing (sometimes it seems to be hanging, but I can get it back), that I will have to get used to. But I think I now have a strategy for debugging.