Help: using msvcrt for file locking

Sheila King sheila at spamcop.net
Mon Aug 27 23:36:08 EDT 2001


On Tue, 28 Aug 2001 03:19:20 GMT, bokr at accessone.com (Bengt Richter)
wrote in comp.lang.python in article
<3b8b0a06.643208765 at wa.news.verio.net>:

:On Mon, 27 Aug 2001 22:54:49 GMT, Sheila King <sheila at spamcop.net> wrote:
:
:>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?
:>:
:Looks like I mistook your goal. I thought you were trying to do something
:that would work on both windows and linux. Or are you testing os.name and
:doing different things?

I want something that will work on both posix and win32.
However, I expect to have to code them differently, and then put a
wrapper around that, so it appears that they both have the same
interface.

On the method used for Windows, I wanted to make it especially clear,
that it had to work for all win32 platforms, since sometimes people
suggest methods that only work for NT/2000.

Anyhow, I want to thank everyone who has made suggestions. All of the
suggestions have been helpful. I'm leaning right now to the
win32file.CreateFile method for the windows code, suggested by David
Bolen. I played around with it a bit this afternoon, and it looks
hopeful.

I expect to use the fcntl.flock (or should I use fcntl.lockf ?) from the
fcntl module for the posix platforms. I understand that it won't work in
some situations where the files are across a network instead of on the
same machine as where the script is running, but I'm not going to worry
about that.

So, I will write two separate modules, one for posix, one for windows,
and then write a module that wraps them both, so that it *appears* to be
cross-platform.

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





More information about the Python-list mailing list