Exemplo n.º 1
0
    def test_start_new_worker(self, instantiate_adapter_executor: SimpleExecutor):
        TestSimpleExecutor._initial()

        _workers = [instantiate_adapter_executor.start_new_worker(target=target_function) for _ in range(_Worker_Size)]
        instantiate_adapter_executor.close(workers=_workers)
        _results = instantiate_adapter_executor.result()
        assert len(_results) == _Worker_Size, ""
        TestSimpleExecutor._chk_run_record(expected_size=Worker_Size)
Exemplo n.º 2
0
    def main_run(self):
        # # # # Initial Executor object
        # __executor = SimpleExecutor(mode=RunningMode.Parallel, executors=self.__Executor_Number)
        # __executor = SimpleExecutor(mode=RunningMode.Concurrent, executors=self.__Executor_Number)
        __executor = SimpleExecutor(mode=RunningMode.GreenThread,
                                    executors=self.__Executor_Number)

        # # # # Generally running with 'start_new_worker'
        _args = ("index_1", "index_2.2")
        _kwargs = {"param_1": "index_1", "param_2": "index_2.2"}
        _workers_list = []
        for _ in range(5):
            _worker = __executor.start_new_worker(
                target=self.__example.target_function)
            # _worker = __executor.start_new_worker(target=self.__example.target_function, args=_args)
            # _worker = __executor.start_new_worker(self.__example.target_function, _args)
            # _worker = __executor.start_new_worker(self.__example.target_function, kwargs=_kwargs)
            _workers_list.append(_worker)
        __executor.close(_workers_list)

        # # # # Running the Executor
        # # # # Generally running
        # __executor.run(
        #     function=self.__example.target_function,
        #     args=("index_1", "index_2.2"))

        # # # # Generally running which will raise exception
        # __executor.run(
        #     function=self.__example.target_fail_function,
        #     args=("index_1", "index_2.2"))

        # # # # Map running which will raise exception
        # __executor.map(
        #     function=self.__example.target_function,
        #     args_iter=[("index_1", "index_2.2"), ("index_3",), (1, 2, 3)])

        # # # # Function version of map running which will raise exception
        # __executor.map_with_function(
        #     functions=[self.__example.target_function, self.__example.target_function],
        #     args_iter=[("index_1", "index_2.2"), ("index_3",), (1, 2, 3)])

        # # # # Get result
        __result = __executor.result()
        print("Result: ", __result)