#!/usr/bin/env python # # We have to mount the same share to test, test1, test2 directories that locate in the directory we # execute this script from. from os import open, close, O_RDWR, O_CREAT, write, read, O_RDONLY, O_WRONLY, O_TRUNC, lseek, SEEK_END, SEEK_SET from fcntl import lockf, LOCK_EX f = open('test/_test4321_', O_RDWR | O_CREAT | O_TRUNC) close(f) f1 = open('test1/_test4321_', O_RDWR) write(f1, 'a') f2 = open('test2/_test4321_', O_WRONLY) lockf(f2, LOCK_EX, 1, 1) lseek(f1, 0, 0) read(f1, 1) f3 = open('test1/_test4321_', O_RDONLY) print read(f3, 1) close(f1) close(f2) close(f3)