Ejemplo n.º 1
0
 def __init__(self, path, threaded=False):
     # pid lockfiles don't support threaded operation, so always force
     # False as the threaded arg.
     LockBase.__init__(self, path, False)
     # dirname = os.path.dirname(self.lock_file)
     # basename = os.path.split(self.path)[-1]
     self.unique_name = self.path
Ejemplo n.º 2
0
    def __init__(self, path, threaded=True):
        """
        >>> lock = SQLiteLockFile('somefile')
        >>> lock = SQLiteLockFile('somefile', threaded=False)
        """
        LockBase.__init__(self, path, threaded)
        self.lock_file = unicode(self.lock_file)
        self.unique_name = unicode(self.unique_name)

        if SQLiteLockFile.testdb is None:
            import tempfile
            _fd, testdb = tempfile.mkstemp()
            os.close(_fd)
            os.unlink(testdb)
            del _fd, tempfile
            SQLiteLockFile.testdb = testdb

        import sqlite3
        self.connection = sqlite3.connect(SQLiteLockFile.testdb)
        
        c = self.connection.cursor()
        try:
            c.execute("create table locks"
                      "("
                      "   lock_file varchar(32),"
                      "   unique_name varchar(32)"
                      ")")
        except sqlite3.OperationalError:
            pass
        else:
            self.connection.commit()
            import atexit
            atexit.register(os.unlink, SQLiteLockFile.testdb)
Ejemplo n.º 3
0
    def __init__(self, path, threaded=True):
        """
        >>> lock = SQLiteLockFile('somefile')
        >>> lock = SQLiteLockFile('somefile', threaded=False)
        """
        LockBase.__init__(self, path, threaded)
        self.lock_file = unicode(self.lock_file)
        self.unique_name = unicode(self.unique_name)

        if SQLiteLockFile.testdb is None:
            import tempfile
            _fd, testdb = tempfile.mkstemp()
            os.close(_fd)
            os.unlink(testdb)
            del _fd, tempfile
            SQLiteLockFile.testdb = testdb

        import sqlite3
        self.connection = sqlite3.connect(SQLiteLockFile.testdb)

        c = self.connection.cursor()
        try:
            c.execute("create table locks"
                      "("
                      "   lock_file varchar(32),"
                      "   unique_name varchar(32)"
                      ")")
        except sqlite3.OperationalError:
            pass
        else:
            self.connection.commit()
            import atexit
            atexit.register(os.unlink, SQLiteLockFile.testdb)
Ejemplo n.º 4
0
 def __init__(self, path, threaded=True):
     """
     >>> lock = MkdirLockFile('somefile')
     >>> lock = MkdirLockFile('somefile', threaded=False)
     """
     LockBase.__init__(self, path, threaded)
     # Lock file itself is a directory.  Place the unique file name into
     # it.
     self.unique_name = os.path.join(
         self.lock_file, "%s.%s%s" % (self.hostname, self.tname, self.pid))
Ejemplo n.º 5
0
 def __init__(self, path, threaded=True):
     """
     >>> lock = MkdirLockFile('somefile')
     >>> lock = MkdirLockFile('somefile', threaded=False)
     """
     LockBase.__init__(self, path, threaded)
     # Lock file itself is a directory.  Place the unique file name into
     # it.
     self.unique_name = os.path.join(self.lock_file,
                                     "%s.%s%s" % (self.hostname,
                                                  self.tname,
                                                  self.pid))