filelock icon indicating copy to clipboard operation
filelock copied to clipboard

Trying to infinetely aquire a lock if flock is not implemented

Open PeterZhizhin opened this issue 4 years ago • 2 comments

I'm using a lustre file system. Looks like it doesn't support flock syscall.

Here is a small script I'm trying to run:

import filelock

t = filelock.FileLock('test.lock')
with t:
  pass

Here is the output:

$ python test.py
... (Runs indefinitely)

Let's try running under strace:

$ strace python test.py
<A lot of garbage>
select(0, NULL, NULL, NULL, {0, 50000}) = 0 (Timeout)
open("test.lock", O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, 0777) = 3
flock(3, LOCK_EX|LOCK_NB)               = -1 ENOSYS (Function not implemented)
close(3)                                = 0
select(0, NULL, NULL, NULL, {0, 50000}) = 0 (Timeout)
open("test.lock", O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, 0777) = 3
flock(3, LOCK_EX|LOCK_NB)               = -1 ENOSYS (Function not implemented)
close(3)                                = 0
select(0, NULL, NULL, NULL, {0, 50000}) = 0 (Timeout)
open("test.lock", O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, 0777) = 3
flock(3, LOCK_EX|LOCK_NB)               = -1 ENOSYS (Function not implemented)
close(3)                                = 0
select(0, NULL, NULL, NULL, {0, 50000}) = 0 (Timeout)
open("test.lock", O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, 0777) = 3
flock(3, LOCK_EX|LOCK_NB)               = -1 ENOSYS (Function not implemented)
close(3)                                = 0
<And so on>

Solution: inside UnixFileLock do not ignore all exceptions. If OSError is raised with errno=ENOSYS, then show a warning, delete the lock file and fallback to SoftFileLock.

PeterZhizhin avatar Apr 16 '20 20:04 PeterZhizhin

Also hitting this issue. Any resolution?

jarednielsen avatar Jun 30 '20 21:06 jarednielsen

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

gaborbernat avatar Sep 27 '21 08:09 gaborbernat