filelock icon indicating copy to clipboard operation
filelock copied to clipboard

Multi-user support for linux

Open hmaarrfk opened this issue 5 years ago • 1 comments

I was wondering if you had any recommendations of using this package in a multi user environment.

We are trying to lock an abstract resource (well a user-land device driver) using the filelock between multipler users potentially connected to a given linux server.

Our original idea was to put a lock file in /tmp. Unfortunately, it seems the sticky bit restricts the usage of the same file by two users.

$ python test_filelock.py 
$ sudo su j -c "/home/mark/miniforge3/envs/dev/bin/python test_filelock.py "
Traceback (most recent call last):
  File "test_filelock.py", line 5, in <module>
    os.ch

mod(lock_filename, 0o777)
PermissionError: [Errno 1] Operation not permitted: '/tmp/my_lock'
$ ls -lah /tmp/my_lock 
-rwxrwxrwx 1 mark mark 0 Jun 23 14:31 /tmp/my_lock

test_filelock.py contains:

from filelock import FileLock
import os
lock_filename = '/tmp/my_lock'
f = FileLock(lock_filename)
os.chmod(lock_filename, 0o777)
f.acquire()
f.release()

If we do find a multi-user solution, would you be interested in merging it in?

As a note, we tried to use SoftFileLock but the fact that the file can persist when python crashes makes it unusable to create a more stable driver.

Using the help from the kernel through fcntl makes FileLock the preferred solution.

hmaarrfk avatar Jun 23 '20 18:06 hmaarrfk

If we do find a multi-user solution, would you be interested in merging it in?

Hello, if you make a PR for this (with tests) we would be happy to review it, thanks!

gaborbernat avatar Sep 27 '21 08:09 gaborbernat