Exclusively lock a file to prevent other processes from reading it?

python at bdurham.com python at bdurham.com
Tue May 4 17:37:51 EDT 2010


Is there a way to exclusively lock a file to prevent other
processes from reading it while we have it open?

I need to cache some overflow data to disk in a temp file and I
want to make sure no other processes can read the contents of
this file while I'm using it.

I tried the following using an 'append binary' mode, but I can
use NotePad to read the file while I'm using it:

fd = open( r'a-temp-file.dat', 'ab' )

My environment is Python 2.6.4 (32-bit) under Windows, but I'm
looking for a cross-platform solution if that's possible.

Thanks,
Malcolm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100504/251ff109/attachment.html>


More information about the Python-list mailing list