9 introduced by Linux 3.15
11 fcntl.F_OFD_GETLK = 36
12 fcntl.F_OFD_SETLK = 37
13 fcntl.F_OFD_SETLKW = 38
16 def handler(signum, frame):
21 f1 = open("testfile", 'w')
22 f2 = open("testfile", 'w')
24 fcntl.flock(f1, fcntl.LOCK_SH | fcntl.LOCK_NB)
27 is flock interruptable?
29 signal.signal(signal.SIGALRM, handler)
32 fcntl.flock(f2, fcntl.LOCK_EX)
34 if e.errno != errno.EINTR:
37 raise RuntimeError("expect flock to block")
39 fcntl.flock(f1, fcntl.LOCK_UN)
41 lockdata = struct.pack('hhllhh', fcntl.F_WRLCK, 0, 0, 10, 0, 0)
43 fcntl.fcntl(f1, fcntl.F_OFD_SETLK, lockdata)
45 if e.errno != errno.EINVAL:
48 print('kernel does not support fcntl.F_OFD_SETLK')
51 lockdata = struct.pack('hhllhh', fcntl.F_WRLCK, 0, 10, 10, 0, 0)
52 fcntl.fcntl(f2, fcntl.F_OFD_SETLK, lockdata)
55 is poxis lock interruptable?
57 signal.signal(signal.SIGALRM, handler)
60 lockdata = struct.pack('hhllhh', fcntl.F_WRLCK, 0, 0, 0, 0, 0)
61 fcntl.fcntl(f2, fcntl.F_OFD_SETLKW, lockdata)
63 if e.errno != errno.EINTR:
66 raise RuntimeError("expect posix lock to block")
69 file handler 2 should still hold lock on 10~10
72 lockdata = struct.pack('hhllhh', fcntl.F_WRLCK, 0, 10, 10, 0, 0)
73 fcntl.fcntl(f1, fcntl.F_OFD_SETLK, lockdata)
75 if e.errno == errno.EAGAIN:
78 raise RuntimeError("expect file handler 2 to hold lock on 10~10")
80 lockdata = struct.pack('hhllhh', fcntl.F_UNLCK, 0, 0, 0, 0, 0)
81 fcntl.fcntl(f1, fcntl.F_OFD_SETLK, lockdata)
82 fcntl.fcntl(f2, fcntl.F_OFD_SETLK, lockdata)