コード例 #1
0
    def testcontendedpyandrust(self):
        with self.ui.configoverride({("devel", "lockmode"):
                                     "python_and_rust"}):
            acquired, released = (0, 0)

            def acquire():
                nonlocal acquired
                acquired += 1

            def release():
                nonlocal released
                released += 1

            with lock.rustlock(self.vfs, "foo"):
                with self.assertRaises(error.LockHeld):
                    lock.trylock(
                        self.ui,
                        self.vfs,
                        "foo",
                        0,
                        acquirefn=acquire,
                        releasefn=release,
                    )

                # Rust still locked
                self.assertLocked("foo")

                # Make sure we released python lock and didn't call any callbacks.
                self.assertLegacyLock("foo", False)
                self.assertEqual(acquired, 0)
                self.assertEqual(released, 0)
コード例 #2
0
ファイル: backuplock.py プロジェクト: xmonader/eden
def trylock(repo):
    try:
        with lockmod.trylock(repo.ui, repo.sharedvfs, lockfilename, 0,
                             0) as lock:
            yield lock
    except error.LockHeld as e:
        if e.lockinfo.isrunning():
            lockinfo = e.lockinfo
            etime = _getprocessetime(lockinfo)
            if etime:
                minutes, seconds = divmod(etime, 60)
                etimemsg = _("\n(pid %s on %s, running for %d min %d sec)") % (
                    lockinfo.uniqueid,
                    lockinfo.namespace,
                    minutes,
                    seconds,
                )
            else:
                etimemsg = ""
            bgstep = _getprogressstep(repo) or "synchronizing"
            repo.ui.status(
                _("background cloud sync is in progress: %s%s\n") %
                (bgstep, etimemsg),
                component="commitcloud",
            )
        raise
コード例 #3
0
    def testpyandrust(self):
        # Lock both python and rust locks.
        with self.ui.configoverride({("devel", "lockmode"):
                                     "python_and_rust"}):
            acquired, prereleased, postreleased = (0, 0, 0)

            def acquire():
                nonlocal acquired
                acquired += 1

            def release():
                nonlocal prereleased
                prereleased += 1

            def postrelease():
                nonlocal postreleased
                postreleased += 1

            with lock.trylock(self.ui,
                              self.vfs,
                              "foo.lock",
                              5,
                              acquirefn=acquire,
                              releasefn=release) as l:
                l.postrelease.append(postrelease)
                self.assertLocked("foo.lock")
                self.assertLegacyLock("foo.lock", True)
                self.assertEqual(acquired, 1)
                self.assertEqual(prereleased, 0)
                self.assertEqual(postreleased, 0)

            self.assertNotLocked("foo.lock")
            self.assertLegacyLock("foo.lock", False)
            self.assertEqual(acquired, 1)
            self.assertEqual(prereleased, 1)
            self.assertEqual(postreleased, 1)