Help: using msvcrt for file locking

David Bolen db3l at fitlinxx.com
Mon Aug 27 18:08:56 EDT 2001


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...

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).  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), but if
you're just using that file to restrict access to other files it can
be a convenient method.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list