-->

Files being served are stale / cached ; Python as

2019-08-30 08:57发布

问题:

I'm serving files in ubuntu using Nginx and fcgi, python and web.py. My index.py contents are:

app = web.application(urls, globals(), True)
if __name__ == "__main__":
    web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)
    app.run()

And I'm launching with:

spawn-fcgi -n -d /usr/share/nginx/www -f ~/Projects/index.py -a 127.0.0.1 -p 9002

Which works fine, EXCEPT, once I make changes to the source files (index.py or any class it includes), those new files are never loaded. I have to stop spawn-fcgi and restart it to see any changes. This make development very cumbersome.

In addition I've turned off the generation of python .pyc/cache files.

TIA

回答1:

I deploy my apps using nginx+uwsgi or apache+mod_wsgi, both of them reload app if I touch code.py. But I run apps from integrated server when developing.

If running web.py integrated server in development mode that has its own reloader is not an option then the only option is to write your own dispatcher with reload functionality.



回答2:

That is most likely by design.

You do normally not want modules reloaded in a production environment (performance, and due to the fact that a module reload in Python does not always have the intended effect).

For development, use some other simpler server model (for example, Django provides its own development server for this exact purpose, I have not used webpy but it appears to have the same functionality according to the tutorial). Use nginx only when deploying the webapp, not in your development environment.

You should not have to bother about .pyc files under normal circumstances (exceptions are in some problematic NFS setups, or when .pyc files are created by the wrong user with the wrong permissions).