示例#1
0
    def test_async_apply_with_iter(self, adapter_pool: AdapterPool):
        TestSimplePool._initial()
        adapter_pool.initial()
        adapter_pool.async_apply_with_iter(functions_iter=target_funcs_iter())
        TestSimplePool._chk_record()

        _results = adapter_pool.get_result()
        TestSimplePool.chk_results(results=_results, expected_size=Task_Size)
示例#2
0
    def test_apply(self, adapter_pool: AdapterPool):
        TestSimplePool._initial()
        adapter_pool.initial()
        adapter_pool.apply(tasks_size=Task_Size, function=target_function)
        TestSimplePool._chk_blocking_record()

        _results = adapter_pool.get_result()
        TestSimplePool.chk_results(results=_results, expected_size=Task_Size)
示例#3
0
    def test_imap_unordered(self, adapter_pool: AdapterPool):
        TestSimplePool._initial()
        adapter_pool.initial()
        adapter_pool.imap_unordered(function=target_function_for_map,
                                    args_iter=Test_Function_Args)
        TestSimplePool._chk_map_record()

        _results = adapter_pool.get_result()
        TestSimplePool.chk_results(results=_results,
                                   expected_size=len(Test_Function_Args))
示例#4
0
    def test_async_map_by_args(self, adapter_pool: AdapterPool):
        TestSimplePool._initial()
        adapter_pool.initial()
        adapter_pool.async_map_by_args(function=target_function_for_map,
                                       args_iter=Test_Function_Multiple_Args)
        TestSimplePool._chk_map_record()

        _results = adapter_pool.get_result()
        TestSimplePool.chk_results(
            results=_results, expected_size=len(Test_Function_Multiple_Args))
示例#5
0
    def test_async_apply_by_pykeyword_with(self, adapter_pool: AdapterPool):
        TestSimplePool._initial()
        with adapter_pool as _pool:
            _pool.async_apply(tasks_size=Task_Size, function=target_function)
        TestSimplePool._chk_record()

        _results = adapter_pool.get_result()
        TestSimplePool.chk_results(results=_results, expected_size=Task_Size)
示例#6
0
    def test_apply_with_iter_by_pykeyword_with(self,
                                               adapter_pool: AdapterPool):
        TestSimplePool._initial()
        with adapter_pool as _pool:
            _pool.apply_with_iter(functions_iter=target_funcs_iter())
        TestSimplePool._chk_blocking_record()

        _results = adapter_pool.get_result()
        TestSimplePool.chk_results(results=_results, expected_size=Task_Size)
示例#7
0
    def test_imap_by_pykeyword_with(self, adapter_pool: AdapterPool):
        TestSimplePool._initial()
        with adapter_pool as _pool:
            _pool.imap(function=target_function_for_map,
                       args_iter=Test_Function_Args)
        TestSimplePool._chk_map_record()

        _results = adapter_pool.get_result()
        TestSimplePool.chk_results(results=_results,
                                   expected_size=len(Test_Function_Args))
示例#8
0
 def test_close(self, adapter_pool: AdapterPool):
     try:
         adapter_pool.initial()
         adapter_pool.async_apply(tasks_size=Task_Size,
                                  function=lambda a: a + a,
                                  args=(1, ))
         adapter_pool.close()
     except Exception:
         assert False, f"It should work finely without any issue. Please check it.\n Error: {traceback.format_exc()}"
     else:
         assert True, "It work finely without any issue."
示例#9
0
    def main_run(self):
        # # # # Initial Executor object
        __pool = AdapterPool(
            strategy=ProcessPoolStrategy(pool_size=self.__Executor_Number,
                                         tasks_size=self.__Executor_Number))
        # __pool = AdapterPool(strategy=ThreadPoolStrategy(pool_size=self.__Executor_Number, tasks_size=self.__Executor_Number))
        # __pool = AdapterPool(strategy=GreenThreadPoolStrategy(pool_size=self.__Executor_Number, tasks_size=self.__Executor_Number))

        __result = None
        with __pool as pool:
            # # # # Running Pool
            # pool.apply(function=self.__Example_Target.target_function, index=f"test_{random.randrange(10,20)}")
            # pool.async_apply(function=self.__Example_Target.target_function, kwargs={"index": f"test_{random.randrange(10,20)}"})
            pool.map(function=self.__Example_Target.target_function,
                     args_iter=("index_1", "index_2.2", "index_3"))
            # pool.map_by_args(function=self.__Example_Target.target_function, args_iter=[("index_1", "index_2.2"), ("index_3",), (1, 2, 3)])

            # # # # Get result
            __result = pool.get_result()

        print("Result: ", __result)
示例#10
0
def adapter_pool() -> AdapterPool:
    set_mode(RunningMode.Concurrent)
    return AdapterPool(strategy=ThreadPoolStrategy(
        pool_size=_Worker_Pool_Size))