title: Python fcntl does not lock as expected
body: <p>On a Debian-based OS (Ubuntu, Debian Squeeze), I'm using Python (2.7, 3.2) fcntl to lock a file. As I understand from what I read, fnctl.flock locks a file in a way, that an exception will be thrown if another client wants to lock the same file.</p>
  
  <p>I built a little example, which I would expect to throw an excepiton, since I first lock the file, and then, immediately after, I try to lock it again:</p>
  
  <pre><code>#!/usr/bin/env python
  # -*- coding: utf-8 -*-
  import fcntl
  fcntl.flock(open('/tmp/locktest', 'r'), fcntl.LOCK_EX)
  try:
      fcntl.flock(open('/tmp/locktest', 'r'), fcntl.LOCK_EX | fcntl.LOCK_NB)
  except IOError:
      print("can't immediately write-lock the file ($!), blocking ...")
  else:
      print("No error")
  </code></pre>
  
  <p>But the example just prints "No error". </p>
  
  <p>If I split this code up to two clients running at the same time (one locking and then waiting, the other trying to lock after the first lock is already active), I get the same behavior - no effect at all.</p>
  
  <p>Whats the explanation for this behavior?</p>
  
  <p><strong>EDIT</strong>:</p>
  
  <p>Changes as requested by nightcracker, this version also prints "No error", although I would not expect that:</p>
  
  <pre><code>#!/usr/bin/env python
  # -*- coding: utf-8 -*-
  import fcntl
  import time
  fcntl.flock(open('/tmp/locktest', 'w'), fcntl.LOCK_EX | fcntl.LOCK_NB)
  try:
      fcntl.flock(open('/tmp/locktest', 'w'), fcntl.LOCK_EX | fcntl.LOCK_NB)
  except IOError:
      print("can't immediately write-lock the file ($!), blocking ...")
  else:
      print("No error")
  </code></pre>