title: python lockf and flock behaviour
body: <p>I have read enough posts on stackoverflow regarding the difference between <code>flock</code>/<code>lockf</code>/<code>fcntl</code> but I am unable to answer the below observation:</p>
  <pre><code>&gt;&gt;&gt; import fcntl
  &gt;&gt;&gt; a = open('/tmp/locktest', 'w')
  &gt;&gt;&gt; b = open('/tmp/locktest', 'w')
  &gt;&gt;&gt; fcntl.lockf(a, fcntl.LOCK_EX | fcntl.LOCK_NB)
  &gt;&gt;&gt; fcntl.lockf(a, fcntl.LOCK_EX | fcntl.LOCK_NB)
  &gt;&gt;&gt; fcntl.lockf(b, fcntl.LOCK_EX | fcntl.LOCK_NB)
  &gt;&gt;&gt;
  &gt;&gt;&gt; a.close()
  &gt;&gt;&gt; b.close()
  
  &gt;&gt;&gt; a = open('/tmp/locktest', 'w')
  &gt;&gt;&gt; b = open('/tmp/locktest', 'w')
  &gt;&gt;&gt; fcntl.flock(a, fcntl.LOCK_EX | fcntl.LOCK_NB)
  &gt;&gt;&gt; fcntl.flock(a, fcntl.LOCK_EX | fcntl.LOCK_NB)
  &gt;&gt;&gt; fcntl.flock(b, fcntl.LOCK_EX | fcntl.LOCK_NB)
  Traceback (most recent call last):
    File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  IOError: [Errno 35] Resource temporarily unavailable
  </code></pre>
  <p>Why is the behaviour different in the two cases? I know the obvious answer that these are two different locking mechanisms. I am looking for:</p>
  <ol>
  <li>What actually <code>lockf()</code> or <code>flock()</code> does to file (<code>inode/fd</code>)?</li>
  <li>As per the demo, are we allowed taking the same lock recursively?</li>
  </ol>
  <p>I understand the basics of <code>fds</code> and stuff so I would prefer to have a technical answer with more insights to operating system level details.</p>
  <p>OSX 10.9.3, Python: 2.7.5</p>