Ticket #9400: nfslocktest.py

File nfslocktest.py, 387 bytes (added by dougvanhorn, 14 years ago)

Small file to test locking as locks.py does, outside of Django.

Line 
1#!/usr/bin/env python
2
3import os
4import fcntl
5
6full_path = "/path/to/nfs-share/locktest.txt"
7f = os.open(full_path, os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os, 'O_BINARY', 0))
8
9def fd(f):
10 return hasattr(f, 'fileno') and f.fileno() or f
11
12try:
13 fcntl.lockf(fd(f), fcntl.LOCK_EX)
14finally:
15 fcntl.lockf(fd(f), fcntl.LOCK_UN)
16 os.close(f)
17 os.remove(full_path)
18
19# EOF
20
Back to Top