(self, lockfile, pid=None)
create (if need be), and acquire lock on lockfile

        lockfile example: '/var/run/up2date.pid'
create (if need be), and acquire lock on lockfile
create ( if need be ) and acquire lock on lockfile
def __init__(self, lockfile, pid=None):
        """create (if need be), and acquire lock on lockfile

        lockfile example: '/var/run/up2date.pid'
        """

        # cleanup the path and assign it.
        self.lockfile = os.path.abspath(
                          os.path.expanduser(
                            os.path.expandvars(lockfile)))

        self.pid = pid
        if not self.pid:
            self.pid = os.getpid()

        # create the directory structure
        dirname = os.path.dirname(self.lockfile)
        if not os.path.exists(dirname):
            try:
                os.makedirs(dirname)
            except OSError, e:
                if hasattr(e, 'errno') and e.errno == EEXIST:
                    # race condition... dirname exists now.
                    pass
                else:
                    raise

        # open the file -- non-destructive read-write, unless it needs
        # to be created XXX: potential race condition upon create?
        self.f = os.open(self.lockfile, os.O_RDWR|os.O_CREAT|os.O_SYNC)
        self.acquire()
def __init__ ( self , lockfile , pid = None ) : # cleanup the path and assign it. self . lockfile = os . path . abspath ( os . path . expanduser ( os . path . expandvars ( lockfile ) ) ) self . pid = pid if not self . pid : self . pid = os . getpid ( ) # create the directory structure dirname = os . path . dirname ( self . lockfile ) if not os . path . exists ( dirname ) : try : os . makedirs ( dirname ) except OSError , e : if hasattr ( e , 'errno' ) and e . errno == EEXIST : # race condition... dirname exists now. pass else : raise # open the file -- non-destructive read-write, unless it needs # to be created XXX: potential race condition upon create? self . f = os . open ( self . lockfile , os . O_RDWR | os . O_CREAT | os . O_SYNC ) self . acquire ( )