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)
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)
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))
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))
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)
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)
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))
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."
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)
def adapter_pool() -> AdapterPool: set_mode(RunningMode.Concurrent) return AdapterPool(strategy=ThreadPoolStrategy( pool_size=_Worker_Pool_Size))