Skip to content

Multi-user support for linux #70

@hmaarrfk

Description

@hmaarrfk

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions