I have a python script which updates some values in a file. This script may be used by more than 1 users, which means that file will be updated by multiple users. But 2 users shouldn't update the file at the same time. If a user is updating the file, the other user should wait for 1st user's script to be completed. Is it possible to check if a file is in use in python? If in use, script should wait, and as soon as it is NOT in use, it should continue and update the file.

有帮助吗?

解决方案

You need some sort of file locking.

I think this gives solution to your problem.

Traditionally this is called a resource sharing problem solved using semaphores, Locking etc.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top