File locking using fcntl.flock()

Richard Jones rjones at ekit-inc.com
Tue Apr 16 19:27:34 EDT 2002


I can't get any locking to work on Solaris 5.7 using python 2.1.3. On Linux 
2.4.9, I get an exception when I try to re-lock something that's locked. On 
Solaris, I don't get the exception (and without LOCK_NB, I don't block 
either). I've also tried the lockf and posixfile.lock methods to no avail.

>>> import fcntl
>>> f=open('foo', 'w')
>>> fcntl.flock(f.fileno(), fcntl.LOCK_EX)
>>> f2=open('foo', 'w')
>>> fcntl.flock(f2.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
IOError: [Errno 11] Resource temporarily unavailable
>>>

I just don't get that exception on Solaris... anyone?



    Richard






More information about the Python-list mailing list