Reputation: 16081
I want to run IPython interactively while running my Flask app. I tried ipython -i app.py
but I don't get a prompt until after the app exits. I want to do this so I can debug each step of the program. How can I run my app and be able to examine it?
Upvotes: 1
Views: 1411
Reputation: 16081
Implemented with thread
from flask import Flask
import thread
data = 'foo'
app = Flask(__name__)
@app.route("/")
def main():
return data
def flaskThread():
app.run()
if __name__ == "__main__":
thread.start_new_thread(flaskThread,())
And open the IPython
Command prompt and type the command run -i filename.py
Upvotes: 0
Reputation: 127260
The -i
flag runs the given program and then puts you in an interactive session after it has run. There is no way to debug the program using this flag.
Instead, you want to use a debugger. python -m pdb app.py
will start pdb, a console debugger. There are other debuggers available, such as the graphical one built into IDEs such as PyCharm and PyDev, or more advanced console ones such as pudb.
Upvotes: 2