Note that there are some explanatory texts on larger screens.

plurals
  1. POPython, WSGI, multiprocessing and shared data
    text
    copied!<p>I am a bit confused about multiproessing feature of mod_wsgi and about a general design of WSGI applications that would be executed on WSGI servers with multiprocessing ability. </p> <p>Consider the following directive:</p> <pre><code>WSGIDaemonProcess example processes=5 threads=1 </code></pre> <p>If I understand correctly, mod_wsgi will spawn 5 Python (e.g. CPython) processes and any of these processes can receive a request from a user. </p> <p>The documentation says that:</p> <blockquote> <p>Where shared data needs to be visible to all application instances, regardless of which child process they execute in, and changes made to the data by one application are immediately available to another, including any executing in another child process, an external data store such as a database or shared memory must be used. Global variables in normal Python modules cannot be used for this purpose.</p> </blockquote> <p>But in that case it gets really heavy when one wants to be sure that an app runs in any WSGI conditions (including multiprocessing ones). </p> <p>For example, a simple variable which contains the current amount of connected users - should it be process-safe read/written from/to memcached, or a DB or (if such out-of-the-standard-library mechanisms are available) shared memory? </p> <p>And will the code like</p> <pre><code>counter = 0 @app.route('/login') def login(): ... counter += 1 ... @app.route('/logout') def logout(): ... counter -= 1 ... @app.route('/show_users_count') def show_users_count(): return counter </code></pre> <p>behave unpredictably in multiprocessing environment?</p> <p>Thank you!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload