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


Python LockDir.wait_lock方法代碼示例

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


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

示例1: test_32_lock_wait_succeed

# 需要導入模塊: from bzrlib.lockdir import LockDir [as 別名]
# 或者: from bzrlib.lockdir.LockDir import wait_lock [as 別名]
    def test_32_lock_wait_succeed(self):
        """Succeed when trying to acquire a lock that gets released

        One thread holds on a lock and then releases it; another 
        tries to lock it.
        """
        # This test sometimes fails like this:
        # Traceback (most recent call last):

        #   File "/home/pqm/bzr-pqm-workdir/home/+trunk/bzrlib/tests/
        # test_lockdir.py", line 247, in test_32_lock_wait_succeed
        #     self.assertEqual(1, len(self._logged_reports))
        # AssertionError: not equal:
        # a = 1
        # b = 0
        raise tests.TestSkipped("Test fails intermittently")
        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.wait_lock(timeout=0.4, poll=0.1)
            after = time.time()
            self.assertTrue(after - before <= 1.0)
        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,代碼行數:54,代碼來源:test_lockdir.py

示例2: test_31_lock_wait_easy

# 需要導入模塊: from bzrlib.lockdir import LockDir [as 別名]
# 或者: from bzrlib.lockdir.LockDir import wait_lock [as 別名]
 def test_31_lock_wait_easy(self):
     """Succeed when waiting on a lock with no contention.
     """
     t = self.get_transport()
     lf1 = LockDir(t, 'test_lock')
     lf1.create()
     self.setup_log_reporter(lf1)
     try:
         before = time.time()
         lf1.wait_lock(timeout=0.4, poll=0.1)
         after = time.time()
         self.assertTrue(after - before <= 1.0)
     finally:
         lf1.unlock()
     self.assertEqual([], self._logged_reports)
開發者ID:GymWenFLL,項目名稱:tpp_libs,代碼行數:17,代碼來源:test_lockdir.py


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