当前位置: 首页>>代码示例>>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;未经允许,请勿转载。