Report this

What is the reason for this report?

Nginx + uwsgi + Flask, Understanding propagation of changes from app.py to deployed stack

Posted on February 9, 2018

Disclaimer & Background: I am a hobbyist programmer trying to learn how to set up a webserver to host replayable text-logs from a game I play. Every thing I know about coding is self taught via Google/Stack Overflow. I am trying to understand the relationship between deployed nginx+uwsgi+flask so I can continue to solve & maintain what I have written so far.

Problem: In short, how do I ensure that changes to .py files that are successfully viewed over the internet served via the virtualenv as well as a cli-run uwsgi can also be successfully viewed over the internet via the defined ip and domain.

Detail: I have successfully followed @jtittle1’s step-by-step solve to a basic nginx+uwsgi+flask set up. The basic site sits here.

This works in virtualenv, cli-run uwsgi, by ip and domain.

When I updated my second page (modifying a placeholder), I can successfully view my changes when running the virtualenv as well as the cli-run uwsgi. However, despite restarting the daemonized services and nginx, I am still viewing my placeholder when I navigate to the specified ip and domain.

I have run into an iteration of this problem before where I had to remove (and allow rebuild of) existing .pyc files. I am not sure this is the problem here as I have removed my existing .pyc files and still view the placeholder page. I have viewed this across multiple naive browsers so it is not a cached response.

My question is: if all of my application is represented by the .py files I have since modified, what on earth am I viewing? Abstractly, nginx is serving me a version of my application that is no longer apparently available to me in my application directory. Where and what is this?

Thanks for your patience!



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

Your Flask application’s state might be getting cached in a few places, which could be preventing your updates from being reflected. Here are a few areas to check:

  • uWSGI: When running Flask with uWSGI, sometimes changes don’t propagate until uWSGI is fully restarted. To ensure uWSGI has fully restarted and picked up your changes, try stopping the service, confirm it has stopped, and then start it back up:
sudo service uwsgi stop
sudo ps aux | grep uwsgi  # Confirm that no uwsgi processes are running
sudo service uwsgi start
  • NGINX: Although it’s less likely, NGINX could potentially be serving cached versions of your app. To ensure NGINX is serving the most up-to-date version of your app, restart the NGINX service:
sudo service nginx restart
  • Browser Cache: As you’ve already suspected, it’s also possible that your browser has cached an old version of your site. Try accessing your site in an incognito/private browsing window, or clear your browser’s cache.

  • Flask Application: Ensure that there are no .pyc or pycache files left in your Flask application’s directory. These are compiled Python bytecode files that could be out of date. You can remove these with:

find /path/to/your/app -name '__pycache__' -delete
find /path/to/your/app -name '*.pyc' -delete
  • Application Config: In your Flask application’s configuration, make sure you have Debug set to False, as the Debug mode can sometimes interfere with how changes propagate in a production environment.

If none of the above steps help, you might have a problem with your Flask application’s code or its interaction with uWSGI or NGINX. It would be helpful to check the logs of each service to look for any errors or warnings.

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.