[Answered ]-Python objects lose state after every request in nginx

2👍

Gunicorn has a preforking worker model — meaning that it launches several independent subprocesses, each of which is responsible for handling a subset of the load.

If you’re relying on internal application state being consistent across all threads involved in offering your service, you’ll want to turn the number of workers down to 1, to ensure that all those threads are within the same process.


Of course, this is a stopgap — if you want to be able to scale your solution to run on production loads, or have multiple servers backing your application, then you’ll want to be modify your system to persist the relevant state to a shared store, rather than relying on content being available in-process.

Leave a comment