File Locking (or any similar file mutex) in Windows OS???

Ron Horn rchii at lycos.com
Wed Jul 3 19:45:56 EDT 2002


OK, I'm kinda new to Python, but I want to setup a simple app that will
allow multiple client machines to examine an modify a SHARED file on some
server.  I want to avoid two clients writing to the file at the same time,
so some sort of (simple!) mutex on the file (or file locking, etc.) is
needed.

All the machines are running Windows of some sort (usually Windows 2000, but
whatever).  I was considering using the "shelve" module to read/write the
shared file.  I've tried several things to determine on one client if
another client has the shelve file open, but to no avail, and the clients
will merrily overwrite each others data.

As a test, I've also tried just using os.open() with various flags (e.g.
O_EXCL), also to no avail.  The clients ignore the fact that the file is
already open by another client.

I would like some simple and robust way to know if one of the clients is
currently using the file, but my question could apply to any shared resource
the various client instances could want to share.  It seems that the various
file locking features of os.open(), and anydbm.open(), etc. are not working
right on Windows?

Any suggestions on how to make this work in python running on windows
clients/server would be appreciated.

ron






More information about the Python-list mailing list