code_junkie

Python: Lock directory access under windows

Nov 13th, 2011
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. def flock(fd, blocking=False, exclusive=False):
  2.  
  3. if exclusive:
  4. flags = fcntl.LOCK_EX
  5. else:
  6. flags = fcntl.LOCK_SH
  7. if not blocking:
  8. flags |= fcntl.LOCK_NB
  9. fcntl.flock(fd, flags)
  10.  
  11. def flock(fd, blocking=False, exclusive=False):
  12.  
  13. if blocking:
  14. flags = msvcrt.LK_NBLCK
  15. else:
  16. flags = msvcrt.LK_LOCK
  17. msvcrt.locking(fd.fileno(), flags, os.path.getsize(fd.name))
  18.  
  19. for file in os.listdir(dir):
  20. f = open(file)
  21. flock(f)
  22.  
  23. open(dirname)
  24.  
  25. OSError: [Errno 13] Permission denied: dirname
Add Comment
Please, Sign In to add comment