Setting an exclusive lock on a file

Eugene Perederey eugene.perederey at
Sun Mar 29 13:26:15 CEST 2009

Hi all,
I want to set an exclusive lock on a file so other processes wouldn't
be able to write to it.
So I write

import fcntl
fcntl.lockf(fd, fcntl.LOCK_EX)
fd.write('some bytes')

But it turns out that my script doesn't write anything to file whereas
other processes do. What's wrong in my code?

Sincerely yours, Eugene Perederey

More information about the Python-list mailing list