Setting an exclusive lock on a file
Diez B. Roggisch
deets at nospam.web.de
Sun Mar 29 08:39:29 EDT 2009
Eugene Perederey schrieb:
> 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
> fd=open('myfile','w')
> fcntl.lockf(fd, fcntl.LOCK_EX)
> fd.write('some bytes')
> fd.close()
>
> But it turns out that my script doesn't write anything to file whereas
> other processes do. What's wrong in my code?
http://code.activestate.com/recipes/65203/
Diez
More information about the Python-list
mailing list