I have a Python flask API wrapped with uWSGI+Nginx for production setup. I have 4 Nginx workers and 1 thread per worker configured as follows, processes = 4 threads = 1.
When I issue an API Post, the post writes and reads a json file at different parts of my code.
When I issue multiple API requests in parallel , it gets distributed to these 4 Nginx workers as expected. And they go ahead and process the request in parallel. Sometimes this causes json ValueErrors as multiple processes are reading and writing to the same file.
How do I overcome this scenario? This is not multiprocessing within my API. So using python's multiprocessing Lock within my json update code will not fix my problem.
I want to be able to update the json files one worker at a time. Is there a way to share locks within uwsgi workers?