How can one open a file for exclusive access?

Syver Enstad syver-en+usenet at online.no
Mon Jan 14 13:49:52 EST 2002


"Alex Martelli" <aleax at aleax.it> writes:
> > I want to be able to open a file for writing exclusively,
> > that while it is open, no other process may read or
> > write to that file.
>     ...
> > So, how, in Python, can one open a file for exclusive
> > access?
> 
> A good example of such file-locking, cross-platform, is at:
> 
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65203
> 

Hmm... I might be mistaken here Alex, but as far as I can remember
this is advisory file locking, where one is using a file as a kind of
synchronization primitive, access to the file is not really affected
at all. So it doesn't solve the problem the poster was addressing;
which was that he didn't want any external program to be able to write
to his file while he had it open. To solve that the only solution I
know of is to use the win32file functions that allows you to specify
this, ie win32file.CreateFile and so on.

-- 

Vennlig hilsen 

Syver Enstad



More information about the Python-list mailing list