0

My settings:

  • Python 3.7.1
  • Flask 1.0.2
  • linux
  • Anaconda3

Problem description: I am running a flask app, and the backend loads a few hundred MB data to a global variable data and it provide information to the front end. I have a server side session to store some user input such as the user selected dates, selected items, etc. currently, I am running the production mode w/ uwsgi (no nginx). It works fine. Except the following problem:

When multiple users are running the app from their browsers, one user see the other user's selections. To me it seems there is only one instance of the backend and when one user update their selections, it also affect other users.

Question: Do I have to use Nginx to allow multiple users to run the app without interference?

Frank
  • 152
  • 2
  • 11
  • The whole point of using WSGI servers is to reuse the same Python process for many requests. Global data in a WSGI server is **not limited to a single request or client**. – Martijn Pieters Mar 21 '19 at 20:52
  • Running a separate process *per browser* does not scale. You need to key your data storage with a unique identifier per client. But take into account that a WSGI server can still spin up several worker processes (a handful, not one per client, and a client can be served by multiple worker processes for different requests). – Martijn Pieters Mar 21 '19 at 20:54
  • I'm not 100% sure, but I think in case of uWSGI setting [`lazy-apps`](https://uwsgi-docs.readthedocs.io/en/latest/articles/TheArtOfGracefulReloading.html#preforking-vs-lazy-apps-vs-lazy) option could help. As I understand it, it instructs uWSGI to spin up a completely independent process for each worker. – Tomáš Linhart Mar 22 '19 at 05:49
  • Thank you Martijn and Tomas, I think my problems come from that I am using global variables and they are not process safe. – Frank Mar 27 '19 at 14:41

0 Answers0