Help: using msvcrt for file locking

Sheila King sheila at spamcop.net
Mon Aug 27 18:54:49 EDT 2001


On 27 Aug 2001 18:08:56 -0400, David Bolen <db3l at fitlinxx.com> wrote in
comp.lang.python in article <uu1ytrw93.fsf at ctwd0143.fitlinxx.com>:

:Sheila King <sheila at spamcop.net> writes:
:
:> I'm trying to do some file locking on Windows. I'm running Win98, but I
:> hope that the methods in the msvcrt module will work OK on any win32?
:
:After reading this thread, it appears that you probably want more fine
:grained locking, but just in case you do end up falling back to some
:sort of sentinel file or more global lock approach...

No, I wasn't trying to do fine grained locking. I was going to use a
sentinel file.

:An alternative to the msvcrt lock stuff for a full file lock that may
:be more portable among Windows platforms would be to just open your
:lock file using the native Win32 CreateFile call (wrapped in
:win32file), and ask for exclusive access (no sharing mode).  

Thanks. I'm looking at that, and it looks like it might be a very good
approach.

:If you need to do I/O to the lock file you'll probably need to use the Win32
:functions (although you could wrap that in a file-like object),

Fortunately, I'm not planning any I/O on the locked file.

:but if you're just using that file to restrict access to other files it can
:be a convenient method.

This is exactly what I'm trying to do. Thanks, again, for the
suggestion.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/




More information about the Python-list mailing list