How to wait for first request to complete then respond to others?

I have an app which is supposed to show some results. In this app, I need to update some files every 30 minutes. In the process of updating, if two or more users load the page, the updating files will be corrupted because they may be overwritten. So, how can I lock the process of updating files in python so that corruption never happen?

Hi @MAmrollahi,

This sounds like a case where you should be writing to a database rather than a single file. If you really can’t avoid writing to a single file simultaneously, I’d recommend checking out this thread
that makes some suggestions re: locking a file via Python.


1 Like