I'm currently attempting to lock a file via python so other processes cannot even read it.

So far i was testing behavior of fcntl.lockf() via python interpreter:

>>> file = open("/path/to/file", "w")
>>> fcntl.lockf(file.fileno(), fcntl.LOCK_EX | fcntl_LOCK_READ)

I've tried this and few other variations of fcntl.lockf but still i was able to open the file second time and obtain his fd. I was able to read it and also write to it.

Am I missing something or this should not lock the file for other procesess at all? Is there any other way to do it?

有帮助吗?

解决方案

It is an advisory lock, that is only a cooperating process will be deterred. See this discussion on how to place a mandatory lock.

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