Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx, uWSGI, Flask app doesn't show changes until the server is restarted

Every time I update my Python file, I have to reboot the server to see changes. I have tried restarting Nginx and uWSGI with no luck. Flask is running in debug mode. How can I see changes without rebooting the entire server?

app.py

from flask import Flask
import time
import cv2

app = Flask(__name__)

@app.route("/")
def main():
   return "Hello cob at " + time.time().__str__() + "\n"

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

uwsgi.ini

[uwsgi]
socket = :9090
plugin = python
wsgi-file = /home/vagrant/PythonVision/app.py
process = 3
callable = app

nginx.conf

server {
  location / {
    include uwsgi_params;
    uwsgi_pass 127.0.0.1:9090;
  }
}

I am testing this with these steps:

  • change the return message from "Hello cob" to "hello bob", save the file
  • Refresh the page in a browser (clear cache of browser) No change
  • Do sudo service uwsgi restart, sudo service nginx restart
  • Refresh the page in a browser (clear cache of browser) No change
like image 269
Burf2000 Avatar asked Sep 19 '25 01:09

Burf2000


2 Answers

So, one way I got around this was to do this in my uwsgi.ini file

touch-reload = /home/vagrant/PythonVision/app.py

Then I touch the file app.py and BANG sorted

like image 196
Burf2000 Avatar answered Sep 21 '25 16:09

Burf2000


To actually run your flask app in debug mode, you run this command:

python /home/vagrant/PythonVision/app.py

Then you can go on your browser: http://ip:5000/.

Since I know you're running this on vagrant, the ip might be defined by your configs, but that's beyond the scope of this question.

like image 41
Rafael Barros Avatar answered Sep 21 '25 14:09

Rafael Barros