Flask app not running after closing putty

最后都变了- 提交于 2021-01-27 13:27:37

问题


I am trying to make a flask web app. whenever i close my putty the website stops running and even if I make any change in the code then without running again it does not reflect on the web.


回答1:


When you close putty, you are virtually closing down your app also, If you want to access it even when you close down your putty, you should have "tmux installed on you system":

pip install tmux

Once installed, create a new tmux session by

tmux new -s myname

Under this session run any code you want (flask app in your case), close the putty and you should still be able to access your app running. You can attach to your session to stop the app via

tmux a -t myname

or you can simply kill your tmux session. For more details please check https://github.com/tmux/tmux/wiki




回答2:


When you close putty, you close the process of running the application too. in order for the app to run, you need to deploy it. i give you an example on how to deploy using Gunicorn and you should read doc's for other way's to deploy yourself.

do a pip install for Gunicorn:

pip install gunicorn

and then,

gunicorn -w 4 -b 127.0.0.1:4000 index:app

the app in the above line is the variable name you gave to instantiate flask.

app = Flask()

so, if you have used something other than app you should put that in the index:app part. index is obviously the filename you have your app inside.

you can make a service and run Gunicorn from a file, so even if your server is restarted, it will run at boot.




回答3:


Ideally you have to run your flask app with gunicorn+nginx refer this tutorial https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-16-04 but for development purpose refer this link to keep your flask app running even after you close your terminal https://askubuntu.com/questions/8653/how-to-keep-processes-running-after-ending-ssh-session



来源:https://stackoverflow.com/questions/48514047/flask-app-not-running-after-closing-putty

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!