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