當前位置: 首頁>>代碼示例>>Python>>正文


Python LockDir.lock_write方法代碼示例

本文整理匯總了Python中bzrlib.lockdir.LockDir.lock_write方法的典型用法代碼示例。如果您正苦於以下問題:Python LockDir.lock_write方法的具體用法?Python LockDir.lock_write怎麽用?Python LockDir.lock_write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在bzrlib.lockdir.LockDir的用法示例。


在下文中一共展示了LockDir.lock_write方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_50_lockdir_representation

# 需要導入模塊: from bzrlib.lockdir import LockDir [as 別名]
# 或者: from bzrlib.lockdir.LockDir import lock_write [as 別名]
    def test_50_lockdir_representation(self):
        """Check the on-disk representation of LockDirs is as expected.

        There should always be a top-level directory named by the lock.
        When the lock is held, there should be a lockname/held directory
        containing an info file.
        """
        t = self.get_transport()
        lf1 = LockDir(t, 'test_lock')
        lf1.create()
        self.assertTrue(t.has('test_lock'))
        lf1.lock_write()
        self.assertTrue(t.has('test_lock/held/info'))
        lf1.unlock()
        self.assertFalse(t.has('test_lock/held/info'))
開發者ID:GymWenFLL,項目名稱:tpp_libs,代碼行數:17,代碼來源:test_lockdir.py

示例2: test_34_lock_write_waits

# 需要導入模塊: from bzrlib.lockdir import LockDir [as 別名]
# 或者: from bzrlib.lockdir.LockDir import lock_write [as 別名]
    def test_34_lock_write_waits(self):
        """LockDir.lock_write() will wait for the lock.""" 
        # the test suite sets the default to 0 to make deadlocks fail fast.
        # change it for this test, as we want to try a manual deadlock.
        raise tests.TestSkipped('Timing-sensitive test')
        bzrlib.lockdir._DEFAULT_TIMEOUT_SECONDS = 300
        t = self.get_transport()
        lf1 = LockDir(t, 'test_lock')
        lf1.create()
        lf1.attempt_lock()

        def wait_and_unlock():
            time.sleep(0.1)
            lf1.unlock()
        unlocker = Thread(target=wait_and_unlock)
        unlocker.start()
        try:
            lf2 = LockDir(t, 'test_lock')
            self.setup_log_reporter(lf2)
            before = time.time()
            # wait and then lock
            lf2.lock_write()
            after = time.time()
        finally:
            unlocker.join()

        # There should be only 1 report, even though it should have to
        # wait for a while
        lock_base = lf2.transport.abspath(lf2.path)
        self.assertEqual(1, len(self._logged_reports))
        self.assertEqual('%s %s\n'
                         '%s\n%s\n'
                         'Will continue to try until %s\n',
                         self._logged_reports[0][0])
        args = self._logged_reports[0][1]
        self.assertEqual('Unable to obtain', args[0])
        self.assertEqual('lock %s' % (lock_base,), args[1])
        self.assertStartsWith(args[2], 'held by ')
        self.assertStartsWith(args[3], 'locked ')
        self.assertEndsWith(args[3], ' ago')
        self.assertContainsRe(args[4], r'\d\d:\d\d:\d\d')
開發者ID:c0ns0le,項目名稱:cygwin,代碼行數:43,代碼來源:test_lockdir.py

示例3: test_create_missing_base_directory

# 需要導入模塊: from bzrlib.lockdir import LockDir [as 別名]
# 或者: from bzrlib.lockdir.LockDir import lock_write [as 別名]
    def test_create_missing_base_directory(self):
        """If LockDir.path doesn't exist, it can be created

        Some people manually remove the entire lock/ directory trying
        to unlock a stuck repository/branch/etc. Rather than failing
        after that, just create the lock directory when needed.
        """
        t = self.get_transport()
        lf1 = LockDir(t, 'test_lock')

        lf1.create()
        self.assertTrue(t.has('test_lock'))

        t.rmdir('test_lock')
        self.assertFalse(t.has('test_lock'))

        # This will create 'test_lock' if it needs to
        lf1.lock_write()
        self.assertTrue(t.has('test_lock'))
        self.assertTrue(t.has('test_lock/held/info'))

        lf1.unlock()
        self.assertFalse(t.has('test_lock/held/info'))
開發者ID:GymWenFLL,項目名稱:tpp_libs,代碼行數:25,代碼來源:test_lockdir.py


注:本文中的bzrlib.lockdir.LockDir.lock_write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。