Mutex a file?

MDK mdk at mdk.com
Fri Feb 15 10:16:19 EST 2002


"Sheila King" <usenet at thinkspot.net> wrote in message
news:a4ghg4.3vv79at.1 at kserver.org...
> On Thu, 14 Feb 2002 16:12:51 -0500, "MDK" <mdk at mdk.com> wrote in
comp.lang.python in
> article <a4h98k$ao2f$1 at ID-98166.news.dfncis.de>:
>
> > I have a file that is to be read to and written from by many Python
scripts
> > running at the same time.
> >
> > Is there a way to put a Mutex on it so that the scripts wait their turn
> > before tyring to open it?
>
> This is a problem I worked on some time back. On most Unices, it is not
> hard to lock the file (which is what you need to do). I guess there are
> some problems if you are working across certain types of networks. On
> WinNT and Win2000 (and probably XP) there is also a great deal of control
> over files and file access. It's the Win9x where you loose a lot of this
> ability. I'm not sure what platform you are running on...if Windows,
> you might want to look in more detail at the win32all libraries from
> Mark Hammond.
>
> Anyhow, here are some links to the discussion I initiated on this topic
> some time back. Read the threads. There are many useful comments.
>
http://groups.google.com/groups?as_umsgid=t7uqot8n8gjm03r2m03md8kfsjuauchqhu
%404ax.com
>
http://groups.google.com/groups?as_umsgid=djsfotomogdeba70gp1cuogjbt5ii3chrb
%404ax.com
>
http://groups.google.com/groups?as_umsgid=bo2ootg61vmposfvsg8gvrks6eqiuss940
%404ax.com
> http://mail.python.org/pipermail/tutor/2001-August/008366.html
>
>
> Here is the module I wrote, and am using in a production environment
> on a Linux server for file locking. Advice given to me re: the
> Windows component of this modules is...well, that it wouldn't be
> recommended to use in a production environment. But who would run
> a production server on a Win98 machine anyhow? So, for me it let's
> me test my scripts on my home Windows machine and then upload it
> to my Linux server and expect the same results.
>
> FWIW, I've pasted the code I'm currently running below my sig.
>
> --
> Sheila King
> http://www.thinkspot.net/sheila/
>
> "When introducing your puppy to an adult cat,
> restrain the puppy, not the cat." -- Gwen Bailey,
> _The Perfect Puppy: How to Raise a Well-behaved Dog_

<code-snipped>

Well I spent half my morning reading the threads and other things referenced
by the threads.  This is a much more complicated (and interesting) subject
than I thought.

The code that you posted is exactly what I need: simple file locking on a
Windows machine.

Thank you for sharing your hard work.





More information about the Python-list mailing list