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


Python DotDict.task_func方法代码示例

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


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

示例1: test_task_raises_unexpected_exception

# 需要导入模块: from socorro.lib.util import DotDict [as 别名]
# 或者: from socorro.lib.util.DotDict import task_func [as 别名]
    def test_task_raises_unexpected_exception(self):
        global count
        count = 0

        def new_iter():
            for x in xrange(10):
                yield (x,)

        my_list = []

        def insert_into_list(anItem):
            global count
            count += 1
            if count == 4:
                raise Exception('Unexpected')
            my_list.append(anItem)

        config = DotDict()
        config.logger = self.logger
        config.number_of_threads = 1
        config.maximum_queue_size = 1
        config.job_source_iterator = new_iter
        config.task_func = insert_into_list
        ttm = ThreadedTaskManagerWithConfigSetup(config)
        try:
            ttm.start()
            time.sleep(0.2)
            assert len(ttm.thread_list) == 1
            assert sorted(my_list) == [0, 1, 2, 4, 5, 6, 7, 8, 9]
            assert len(my_list) == 9
        except Exception:
            # we got threads to join
            ttm.wait_for_completion()
            raise
开发者ID:stephendonner,项目名称:socorro,代码行数:36,代码来源:test_threaded_task_manager.py

示例2: test_doing_work_with_two_workers_and_config_setup

# 需要导入模块: from socorro.lib.util import DotDict [as 别名]
# 或者: from socorro.lib.util.DotDict import task_func [as 别名]
    def test_doing_work_with_two_workers_and_config_setup(self):
        def new_iter():
            for x in xrange(5):
                yield ((x,), {})

        my_list = []

        def insert_into_list(anItem):
            my_list.append(anItem)

        config = DotDict()
        config.logger = self.logger
        config.number_of_threads = 2
        config.maximum_queue_size = 2
        config.job_source_iterator = new_iter
        config.task_func = insert_into_list
        ttm = ThreadedTaskManagerWithConfigSetup(config)
        try:
            ttm.start()
            time.sleep(0.2)
            ok_(len(ttm.thread_list) == 2,
                            "expected 2 threads, but found %d"
                              % len(ttm.thread_list))
            ok_(len(my_list) == 5,
                            'expected to do 5 inserts, '
                              'but %d were done instead' % len(my_list))
            ok_(sorted(my_list) == range(5),
                            'expected %s, but got %s' % (range(5),
                                                         sorted(my_list)))
        except Exception:
            # we got threads to join
            ttm.wait_for_completion()
            raise
开发者ID:JisJis,项目名称:socorro,代码行数:35,代码来源:test_threaded_task_manager.py

示例3: test_doing_work_with_two_workers_and_config_setup

# 需要导入模块: from socorro.lib.util import DotDict [as 别名]
# 或者: from socorro.lib.util.DotDict import task_func [as 别名]
    def test_doing_work_with_two_workers_and_config_setup(self):
        def new_iter():
            for x in xrange(5):
                yield ((x,), {})

        my_list = []

        def insert_into_list(anItem):
            my_list.append(anItem)

        config = DotDict()
        config.logger = self.logger
        config.number_of_threads = 2
        config.maximum_queue_size = 2
        config.job_source_iterator = new_iter
        config.task_func = insert_into_list
        ttm = ThreadedTaskManagerWithConfigSetup(config)
        try:
            ttm.start()
            time.sleep(0.2)
            assert len(ttm.thread_list) == 2
            assert len(my_list) == 5
            assert sorted(my_list) == list(range(5))
        except Exception:
            # we got threads to join
            ttm.wait_for_completion()
            raise
开发者ID:stephendonner,项目名称:socorro,代码行数:29,代码来源:test_threaded_task_manager.py


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