fcntl problems

mhearne808[insert-at-sign-here]gmail[insert-dot-here]com mhearne808 at gmail.com
Fri Aug 31 00:19:37 CEST 2007


I'm having a number of problems with the fcntl module.  First off, my
system info:

Mac OS X
Darwin igskcicglthearn.cr.usgs.gov 8.10.1 Darwin Kernel Version
8.10.1: Wed May 23 16:33:00 PDT 2007; root:xnu-792.22.5~1/RELEASE_I386
i386 i386
Python 2.5.1 (built from source)

OK, the weirdness:

First of all, if I try this:
file = open("counter.txt","w+")
fcntl.flock(file.fileno(), fcntl.LOCK_NB)

I get this:
---------------------------------------------------------------------------
<type 'exceptions.IOError'>               Traceback (most recent call
last)
/Users/mhearne/src/python/<ipython console> in <module>()
<type 'exceptions.IOError'>: [Errno 9] Bad file descriptor

However, if I try this:
fcntl.flock(file.fileno(), fcntl.LOCK_EX)

I get no errors.

Proceeding forward with the locked file, let's say I do the above in
Python interactive Process A.  Then in python interactive Process B, I
repeat the "open" function on the same file with the same
permissions.  Then, in each process, I write some text to the file
using the write() method.  After closing the file in both processes,
the only text I see in the file is from Process B!

According to my Python Cookbook:
"Exclusive lock: This denies all _other_ processes both read and write
access to the file."

I seem to be experiencing the reverse of that description.  Is this my
lack of understanding, or have I discovered a bug?

Thanks,

Mike




More information about the Python-list mailing list