[Django]-Are module level variables safe when used with uWSGI?

3👍

I wanted to circle back and explain what happened here. Global variables are, in fact, not “refreshed” between requests to the same service in uWSGI. Thus, if you create a module level variable, it will carry state between multiple requests. This, obviously, was not what I intended; so I ended up passing a caching object around between the different calls into XMLGenerator. It caused the API to be quite ugly, but avoided the issue with module-level variables.

1👍

If you are doing this with multiple workers than you probably want to use uwsig’s CachingFramework:

http://projects.unbit.it/uwsgi/wiki/CachingFramework

Otherwise I believe _cache can be different across the workers.

Also, you could test with uwsgi –processes 1 to see if the problem goes away.

Leave a comment