lockfile.py 356 B

123456789101112131415
  1. import struct, fcntl
  2. def writelock(f):
  3. _lock(f, fcntl.F_WRLCK)
  4. def readlock(f):
  5. _lock(f, fcntl.F_RDLCK)
  6. def unlock(f):
  7. _lock(f, fcntl.F_UNLCK)
  8. def _lock(f, op):
  9. dummy = fcntl.fcntl(f.fileno(), fcntl.F_SETLKW,
  10. struct.pack('2h8l', op,
  11. 0, 0, 0, 0, 0, 0, 0, 0, 0))