Вопрос

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