예제 #1
0
    def test_uncleanlyAcquire(self):
        """
        If a lock was held by a process which no longer exists, it can be
        acquired, the C{clean} attribute is set to C{False}, and the
        C{locked} attribute is set to C{True}.
        """
        owner = 12345

        def fakeKill(pid, signal):
            if signal != 0:
                raise OSError(errno.EPERM, None)
            if pid == owner:
                raise OSError(errno.ESRCH, None)

        lockf = self.mktemp()
        self.patch(lockfile, 'kill', fakeKill)
        lockfile.symlink(str(owner), lockf)

        lock = lockfile.FilesystemLock(lockf)
        self.assertTrue(lock.lock())
        self.assertFalse(lock.clean)
        self.assertTrue(lock.locked)

        self.assertEqual(lockfile.readlink(lockf), str(os.getpid()))
예제 #2
0
 def fakeReadlink(name):
     # Pretend to be another process releasing the lock.
     lockfile.rmlink(lockf)
     # Fall back to the real implementation of readlink.
     readlinkPatch.restore()
     return lockfile.readlink(name)
 def fakeReadlink(name):
     # Pretend to be another process releasing the lock.
     lockfile.rmlink(lockf)
     # Fall back to the real implementation of readlink.
     readlinkPatch.restore()
     return lockfile.readlink(name)