Issue
Let me try to explain my problem with example now.
Here is sample GUI code with Tkinter
from Tkinter import *
root = Tk()
w = Label(root, text="Hello, world!")
w.pack()
root.mainloop()
If I run this code in Ipython, I don't get a command prompt when the GUI is visible. Now if I comment out the line, "root.mainloop()", the code still works in Ipython and I have access to command prompt so that I can inspect data when the code is running.
Now coming to the Flask case,
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
app.run()
When I run this application in Ipython, I don't get a command prompt. To access variables while the code is running, I need to stop the flask server.
Is there any option to run the flask server and have access to command prompt?
Thank you
Solution
run the flask application in separate thread. try this example:-
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,())
run this file in ipython:- "run -i filename.py" then you can access the ipython terminal for inspection.
Answered By - Rashid Mv
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.