title: Python "FileExists" error when making directory
body: <p>I have several threads running in parallel from Python on a cluster system. Each python thread outputs to a directory <code>mydir</code>. Each script, before outputting checks if <em>mydir</em> exists and if not creates it:</p>
  
  <pre><code>if not os.path.isdir(mydir):
      os.makedirs(mydir)
  </code></pre>
  
  <p>but this yields the error:</p>
  
  <pre><code>os.makedirs(self.log_dir)                                             
    File "/usr/lib/python2.6/os.py", line 157, in makedirs
  mkdir(name,mode)
  OSError: [Errno 17] File exists
  </code></pre>
  
  <p>I suspect it might be due to a race condition, where one job creates the <em>dir</em> before the other gets to it. Is this possible? If so, how can this error be avoided? </p>
  
  <p>I'm not sure it's a race condition so was wondering if other issues in Python can cause this odd error.</p>