I have a flask App. I am creating 4 workers with Gunicorn. So, on running this,
I will have total 4 flask instances, 4 PIDs and 4 workers. I want to use a python dictionary across all these workers.
I have tried using list from multiprocessing Manager, but it works only for Same PID, it doesn't work for different PID(s).
import multiprocessing
manager = multiprocessing.Manager()
shared_list = manager.list()
Every time a PID is different, I will get a different result.
I prefer to do this without using any Database, Redis, Or such things.
You can use multiprocessing.Manager() + preload flag. Here is an example:
Run app:
gunicorn -w 4 --preload debug:app. Let's check counters:run
python test.py. You'll see thattotalvalue is always the same for different workers /pid's