[Tutor] O_EXLOCK ?

jb jb at riseup.net
Tue Jan 6 01:45:50 EST 2004


On Tue, Jan 06, 2004 at 04:18:34PM +1100, Andrew McNamara wrote:
> >> All the common O_ symbols are defined in the "os" module, but O_EXLOCK
> >> is not standard (not part of the Single Unix spec [1]) - it's a BSD
> >> extension. That's not to say it couldn't be added to "os" at a future
> >> time, but that won't help you in the short term. There is, however, a
> >> "posixfile" module that may do what you need.
> >
> >It hurts that O_EXLOCK and O_SHLOCK are only BSD extensions.  Plan was to
> >use O_EXLOCK for concurrent pickling and unpickling and now i guess i'll
> >enter homegrown locking solutions madness.
> 
> You can still use fcntl locking (as provided by posixfile) - no need to
> invent something bodgy. It really doesn't matter that you have to open the
> file first, provided you don't change it until you gain the lock.

agreed, but oops, i shoud have said that i found the situation problematic 
only at file creation time.  When a file already exists and contains pickled 
data there's no problem and fcntl locking permits that the file stays in a 
consistent state (for pickle).  

when a file is to be created and process A (wanting to dump a pickled object)
and B (wanting to read a pickled object) are competing, there's the possibility
that B gain the lock and start reading just after A has created the file - 
then pickle in B will raise an EOFError (or something).  I was concerned by
this.

but i can dump my object to a temporary file, and then link(2), this looks ok
for my needs.

thanks,
jb




More information about the Tutor mailing list