当前位置: 首页>>代码示例>>Python>>正文


Python threading.BrokenBarrierError方法代码示例

本文整理汇总了Python中threading.BrokenBarrierError方法的典型用法代码示例。如果您正苦于以下问题:Python threading.BrokenBarrierError方法的具体用法?Python threading.BrokenBarrierError怎么用?Python threading.BrokenBarrierError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在threading的用法示例。


在下文中一共展示了threading.BrokenBarrierError方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BrokenBarrierError [as 别名]
def run(self) -> None:
        while not self.stop_event.is_set():

            try:
                self.fetch_barrier.wait()
                self.execute_barrier.wait()
                self.execute_barrier.wait()
                self.call_commands()
            except BrokenBarrierError:
                self.fetch_barrier.abort()
                self.execute_barrier.abort()
                self.stop_event.set()
            else:
                tick_time = time.time()
                process_time = time.process_time()
                if self.last_tick_time:
                    self.do_tick(process_time, tick_time)

                self.last_tick_time = tick_time
                self.last_process_time = process_time
                self.tick_count += 1

                if self.tick_interval:
                    sleep_interval = self.tick_interval - self.tick_adjustment
                    sleep(max(sleep_interval, 0)) 
开发者ID:johnbywater,项目名称:eventsourcing,代码行数:27,代码来源:runner.py

示例2: test_abort

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BrokenBarrierError [as 别名]
def test_abort(self):
        """
        Test that an abort will put the barrier in a broken state
        """
        results1 = []
        results2 = []
        def f():
            try:
                i = self.barrier.wait()
                if i == self.N//2:
                    raise RuntimeError
                self.barrier.wait()
                results1.append(True)
            except threading.BrokenBarrierError:
                results2.append(True)
            except RuntimeError:
                self.barrier.abort()
                pass

        self.run_threads(f)
        self.assertEqual(len(results1), 0)
        self.assertEqual(len(results2), self.N-1)
        self.assertTrue(self.barrier.broken) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:25,代码来源:lock_tests.py

示例3: _test_reset_f

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BrokenBarrierError [as 别名]
def _test_reset_f(cls, barrier, results1, results2, results3):
        i = barrier.wait()
        if i == cls.N//2:
            # Wait until the other threads are all in the barrier.
            while barrier.n_waiting < cls.N-1:
                time.sleep(0.001)
            barrier.reset()
        else:
            try:
                barrier.wait()
                results1.append(True)
            except threading.BrokenBarrierError:
                results2.append(True)
        # Now, pass the barrier again
        barrier.wait()
        results3.append(True) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:_test_multiprocessing.py

示例4: _test_abort_and_reset_f

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BrokenBarrierError [as 别名]
def _test_abort_and_reset_f(cls, barrier, barrier2,
                                results1, results2, results3):
        try:
            i = barrier.wait()
            if i == cls.N//2:
                raise RuntimeError
            barrier.wait()
            results1.append(True)
        except threading.BrokenBarrierError:
            results2.append(True)
        except RuntimeError:
            barrier.abort()
        # Synchronize and reset the barrier.  Must synchronize first so
        # that everyone has left it when we reset, and after so that no
        # one enters it before the reset.
        if barrier2.wait() == cls.N//2:
            barrier.reset()
        barrier2.wait()
        barrier.wait()
        results3.append(True) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:22,代码来源:_test_multiprocessing.py

示例5: test_reset

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BrokenBarrierError [as 别名]
def test_reset(self):
        """
        Test that a 'reset' on a barrier frees the waiting threads
        """
        results1 = []
        results2 = []
        results3 = []
        def f():
            i = self.barrier.wait()
            if i == self.N//2:
                # Wait until the other threads are all in the barrier.
                while self.barrier.n_waiting < self.N-1:
                    time.sleep(0.001)
                self.barrier.reset()
            else:
                try:
                    self.barrier.wait()
                    results1.append(True)
                except threading.BrokenBarrierError:
                    results2.append(True)
            # Now, pass the barrier again
            self.barrier.wait()
            results3.append(True)

        self.run_threads(f)
        self.assertEqual(len(results1), 0)
        self.assertEqual(len(results2), self.N-1)
        self.assertEqual(len(results3), self.N) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:30,代码来源:lock_tests.py

示例6: test_abort_and_reset

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BrokenBarrierError [as 别名]
def test_abort_and_reset(self):
        """
        Test that a barrier can be reset after being broken.
        """
        results1 = []
        results2 = []
        results3 = []
        barrier2 = self.barriertype(self.N)
        def f():
            try:
                i = self.barrier.wait()
                if i == self.N//2:
                    raise RuntimeError
                self.barrier.wait()
                results1.append(True)
            except threading.BrokenBarrierError:
                results2.append(True)
            except RuntimeError:
                self.barrier.abort()
                pass
            # Synchronize and reset the barrier.  Must synchronize first so
            # that everyone has left it when we reset, and after so that no
            # one enters it before the reset.
            if barrier2.wait() == self.N//2:
                self.barrier.reset()
            barrier2.wait()
            self.barrier.wait()
            results3.append(True)

        self.run_threads(f)
        self.assertEqual(len(results1), 0)
        self.assertEqual(len(results2), self.N-1)
        self.assertEqual(len(results3), self.N) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:35,代码来源:lock_tests.py

示例7: test_timeout

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BrokenBarrierError [as 别名]
def test_timeout(self):
        """
        Test wait(timeout)
        """
        def f():
            i = self.barrier.wait()
            if i == self.N // 2:
                # One thread is late!
                time.sleep(1.0)
            # Default timeout is 2.0, so this is shorter.
            self.assertRaises(threading.BrokenBarrierError,
                              self.barrier.wait, 0.5)
        self.run_threads(f) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:15,代码来源:lock_tests.py

示例8: test_default_timeout

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BrokenBarrierError [as 别名]
def test_default_timeout(self):
        """
        Test the barrier's default timeout
        """
        # create a barrier with a low default timeout
        barrier = self.barriertype(self.N, timeout=0.3)
        def f():
            i = barrier.wait()
            if i == self.N // 2:
                # One thread is later than the default timeout of 0.3s.
                time.sleep(1.0)
            self.assertRaises(threading.BrokenBarrierError, barrier.wait)
        self.run_threads(f) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:15,代码来源:lock_tests.py

示例9: _test_timeout_f

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BrokenBarrierError [as 别名]
def _test_timeout_f(cls, barrier, results):
        i = barrier.wait()
        if i == cls.N//2:
            # One thread is late!
            time.sleep(1.0)
        try:
            barrier.wait(0.5)
        except threading.BrokenBarrierError:
            results.append(True) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:_test_multiprocessing.py

示例10: _test_default_timeout_f

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BrokenBarrierError [as 别名]
def _test_default_timeout_f(cls, barrier, results):
        i = barrier.wait(cls.defaultTimeout)
        if i == cls.N//2:
            # One thread is later than the default timeout
            time.sleep(1.0)
        try:
            barrier.wait()
        except threading.BrokenBarrierError:
            results.append(True) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:_test_multiprocessing.py


注:本文中的threading.BrokenBarrierError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。