Please read this before reporting a bug:
https://wiki.archlinux.org/title/Bug_reporting_guidelines
Do NOT report bugs when a package is just outdated, or it is in the AUR. Use the 'flag out of date' link on the package page, or the Mailing List.
REPEAT: Do NOT report bugs for outdated packages!
https://wiki.archlinux.org/title/Bug_reporting_guidelines
Do NOT report bugs when a package is just outdated, or it is in the AUR. Use the 'flag out of date' link on the package page, or the Mailing List.
REPEAT: Do NOT report bugs for outdated packages!
FS#79979 - RFE: python - consider adding support for open file descriptor locking
Attached to Project:
Arch Linux
Opened by Gene (GeneC) - Sunday, 15 October 2023, 23:35 GMT
Last edited by Toolybird (Toolybird) - Monday, 16 October 2023, 19:24 GMT
Opened by Gene (GeneC) - Sunday, 15 October 2023, 23:35 GMT
Last edited by Toolybird (Toolybird) - Monday, 16 October 2023, 19:24 GMT
|
DetailsDescription:
For your consideration: Linux has supported (non-posix) open file descriptor locks for several years. Python supports them as of 3.9 per the docs [1]. They do offer some advantages over Posix locks. see e.g. [3] They are: fcntl.F_OFD_SETLK and fcntl.F_OFD_GETLK However they dont work in our python 3.11.5. I confirmed they work fine in C-code but to compile they need [2] : _GNU_SOURCE to be defined at compile time. Maybe that is helpful in changing the python build to get them working. Thanks! gene [1] https://docs.python.org/3/library/fcntl.html [2] https://www.gnu.org/software/libc/manual/html_node/Open-File-Description-Locks.html [3] https://lwn.net/Articles/586904/ |
This task depends upon
Closed by Toolybird (Toolybird)
Monday, 16 October 2023, 19:24 GMT
Reason for closing: Not a bug
Additional comments about closing: "Not a bug - just my own coding bug."
Monday, 16 October 2023, 19:24 GMT
Reason for closing: Not a bug
Additional comments about closing: "Not a bug - just my own coding bug."
??? Surely it's a bug then, and not a feature request? Please provide "Steps to reproduce".
Python 3.11.5 (main, Sep 2 2023, 14:16:33) [GCC 13.2.1 20230801] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import fcntl
>>> import struct
>>> fcntl.F_OFD_GETLK
36
>>> fcntl.F_OFD_SETLK
37
>>> lockdata = struct.pack('hhllhh', fcntl.F_WRLCK, 0, 0, 10, 0, 0)
>>> f1 = open("testfile", 'w')
>>> try:
... fcntl.fcntl(f1, fcntl.F_OFD_SETLK, lockdata)
... except IOError as e:
... if e.errno != errno.EINVAL:
... raise
... else:
... print('kernel does not support fcntl.F_OFD_SETLK')
... raise
...
b'\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Edit:
Test use of constant as well as presence.
Code and tests attached.
Notes:
C-code implemtation
-------------------
flock_sizes.c = print size of struct flock
c_lock_test.c = c-code locking with and without OFD
build :
make
- to see size of struct flock elements:
./flock_sizes
Tests
-------------------
Test 1) Using F_SETLK
locking use 2 terminals. run c_lock_test in both.
First will acquire lock second will fail (until first exits)
./c_lock_test
Test 2) Using F_OFD_SETLK
repeat test but with argument to turn on OFD
./c_lock_test ofd
Test (1) and (2) both work.
Python:
-------------------
run test in 2 terminals as above:
Test 3) Using F_SETLK
./lock_test.py
Test 4) Using F_OFD_SETLK
./lock_test.py ofd
Test (3) works, but (4) fails to acquire lock.
Edit:
If you adjust the tests from [1] to be standalone, do they pass for you?
[1] https://github.com/ceph/ceph/blob/main/qa/workunits/fs/misc/filelock_interrupt.py
When using OFD the lockdata cannot contain pid - it has to be 0.
Changing line 73 of my python to:
l_pid = 0
Makes it work - very sorry for noise - and thanks for helping me fix my stuff :-
The struct table is here: https://docs.python.org/3/library/struct.html
I used flock_sizes to get the correct values.