Exemple #1
0
    def main_run(self):
        # test_dao = TestDao(connection_strategy=self.persistence_strategy())
        test_dao = TestDao(db_driver="mysql", use_pool=False)

        # # # # Initial and instantiate feature object: Queue Task, Lock and Bounded Semaphore
        _queue_task = self.__init_queue()
        _features = self.__init_features()

        _pool = SimplePool(
            mode=RunningMode.Parallel,
            # mode=RunningMode.Concurrent,
            # mode=RunningMode.GreenThread,
            pool_size=self.__Pool_Size)

        _pool.initial(queue_tasks=_queue_task, features=_features)
        _pool.async_apply(function=test_dao.get_test_data, tasks_size=self.__Pool_Size)
        result = _pool.get_result()

        print("Result: ", result)
        for r in result:
            print(f"+====================================+")
            print("Result.data: ", r.data)
            print("Result.is_successful: ", r.is_successful)
            print("+====================================+\n")

        self.__save_to_files(result=result)

        end_time = time.time()
        self.__logger.info(f"Total taking time: {end_time - start_time} seconds")
Exemple #2
0
    def test_async_apply(self, simple_pool: SimplePool):
        TestSimplePool._initial()
        simple_pool.initial()
        simple_pool.async_apply(tasks_size=Task_Size, function=target_function)
        TestSimplePool._chk_record()

        _results = simple_pool.get_result()
        TestSimplePool.chk_results(results=_results, expected_size=Task_Size)
Exemple #3
0
 def test_close(self, thread_pool: SimplePool):
     try:
         thread_pool.initial()
         thread_pool.async_apply(tasks_size=Task_Size,
                                 function=lambda a: a + a,
                                 args=(1, ))
         thread_pool.close()
     except Exception as e:
         assert False, "It should work finely without any issue. Please check it."
     else:
         assert True, "It work finely without any issue."
Exemple #4
0
 def test_close(self, simple_pool: SimplePool):
     try:
         simple_pool.initial()
         simple_pool.async_apply(tasks_size=Task_Size,
                                 function=lambda a: a + a,
                                 args=(1, ))
         simple_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."
Exemple #5
0
 def test_async_apply(self, thread_pool: SimplePool):
     TestSimplePool._initial()
     thread_pool.initial()
     thread_pool.async_apply(tasks_size=Task_Size, function=pool_target_fun)
     TestSimplePool._chk_record()
Exemple #6
0
# Import package multirunnable
import pathlib
import random
import time
import sys

package_path = str(pathlib.Path(__file__).parent.parent.parent.absolute())
sys.path.append(package_path)

from multirunnable import SimplePool, RunningMode


def function(index):
    print(f"This isfunction with index {index}")
    time.sleep(3)
    return "Return Value"


pool = SimplePool(mode=RunningMode.Parallel, pool_size=3)
pool.initial()
pool.async_apply(function=function,
                 kwargs={"index": f"test_{random.randrange(1, 10)}"},
                 tasks_size=3)
pool.close()
result = pool.get_result()
print(f"This is final result: {result}")