Linux file locks ?

Greg Ewing (using news.cis.dfn.de) me at privacy.net
Thu Mar 27 18:49:59 EST 2003


Padraig at Linux.ie wrote:
> Another option for atomic (cooperative) locking is to
> just try create a directory.

Another one sometimes used is to create a symbolic
link. (The link doesn't have to point anywhere
valid, as its existence is the only thing that
matters. You can use the link contents to hold
some identifying information if you want.)

It's nice and easy to do in Python, too:

Python 2.2 (#1, Jul 11 2002, 14:19:37)
[GCC 3.0.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import os
 >>> os.symlink("foo", "blarg")
 >>> os.symlink("foo", "blarg")
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
OSError: [Errno 17] File exists

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg





More information about the Python-list mailing list