<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Grant Edwards wrote:<br>
<blockquote cite="mid415c212d$0$10209$a1866201@newsreader.visi.com"
 type="cite">
  <pre wrap="">On 2004-09-30, Nigel King <a class="moz-txt-link-rfc2396E" href="mailto:nigel.king@orthogonsystems.com"><nigel.king@orthogonsystems.com></a> wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">On 30 Sep 2004, at 14:11, C Ginger wrote:

    </pre>
    <blockquote type="cite">
      <pre wrap="">I know the approach to creating a lock file has been around a
long time but there are certain weaknesses to it. There are a
number of race conditions in it. For instance if process A
detects the directory isn't there it will attempt to create
it. During that same time process B might also not find it
there - since A hasn't completed its create yet.
      </pre>
    </blockquote>
    <pre wrap="">This was why I created a directory rather than a file since I
thought this was supposed to be atomic.
    </pre>
  </blockquote>
  <pre wrap=""><!---->
AFAIK, creating a file is atomic as well. It's the approach
that's been used by Unix applications for the past 30 years, so
if it wasn't atomic, I would think somebody else would have
noticed the problem and switched to using a lock directory
before now.

  </pre>
</blockquote>
Right.  But I think the OP's point was that os.mkdir() raises an
exception if a directory already exists, so you can wrap that in a
while loop and just keep doing<br>
<br>
try:<br>
    os.mkdir('/foo')<br>
except OSError:<br>
    time.sleep(1)<br>
#do stuff<br>
os.rmdir()<br>
<br>
<br>
and once you get in the #do stuff section, you know you have an
exclusive lock.  Until this posting, I didn't know that:<br>
<br>
os.open('f.txt', os.O_CREAT, os.O_EXCL)<br>
<br>
would basically do the same thing.<br>
<br>
<br>
Jeremy Jones<br>
</body>
</html>