title: Appending to the end of a file in a concurrent environment
body: <p>What steps need to be taken to ensure that "full" lines are <strong>always</strong> correctly appended to the end of a file if multiple of the following (example) program are running concurrently.</p>
  
  <pre><code>#!/usr/bin/env python
  import random
  passwd_text=open("passwd.txt","a+")
  u=("jsmith:x:1001:1000:Joe Smith,Room 1007,(234)555-8917,(234)555-0077,jsmith@rosettacode.org:/home/jsmith:/bin/sh",
    "jdoe:x:1002:1000:Jane Doe,Room 1004,(234)555-8914,(234)555-0044,jdoe@rosettacode.org:/home/jdoe:/bin/sh",
    "xyz:x:1003:1000:X Yz,Room 1003,(234)555-8913,(234)555-0033,xyz@rosettacode.org:/home/xyz:/bin/sh")
  for i in range(random.randint(1,2)):
    print &gt;&gt; passwd_text, random.choice(u)
  passwd_text.close()
  </code></pre>
  
  <p>And: Can an "all or nothing" append be guaranteed (on linux/unix) even if the the disk becomes full, or "ulimit -f" has been set?</p>
  
  <p>(Note similar question: <a href="https://stackoverflow.com/questions/4706499/how-do-you-append-to-file-in-python">How do you append to a file?</a>)</p>