예제 #1
0
    def main_run(self):
        test_dao = TestDao(db_driver="mysql", use_pool=False)
        # test_dao = AsyncTestDao(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()

        _executor = SimpleExecutor(
            mode=RunningMode.Parallel,
            # mode=RunningMode.Concurrent,
            # mode=RunningMode.GreenThread,
            # mode=RunningMode.Asynchronous,
            executors=self.__Worker_Number)

        _executor.run(function=test_dao.get_test_data,
                      queue_tasks=_queue_task,
                      features=_features)
        result = _executor.result()

        for r in result:
            print(f"+============ {r.worker_ident} =============+")
            print("Result.pid: ", r.pid)
            print("Result.worker_id: ", r.worker_ident)
            print("Result.worker_name: ", r.worker_name)
            print("Result.state: ", r.state)
            print("Result.data: ", r.data)
            print("Result.exception: ", r.exception)
            print("+====================================+\n")

        self.__save_to_files(result=result)

        end_time = time.time()
        self.__logger.info(
            f"Total taking time: {end_time - start_time} seconds")
    def main_run(self):
        # Initialize Lock object
        __rlock = RLockFactory()

        # # # # 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)

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

        # # # # 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)],
        #     features=__rlock)

        # # # # 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)],
        #     features=__rlock)

        # # # # Get result
        __result = __executor.result()
        print("Result: ", __result)
예제 #3
0
    def main_run(cls):
        # Initialize Condition object
        __condition = ConditionFactory()

        # Initialize Queue object
        __task = QueueTask()
        __task.name = "test_queue"
        # __task.queue_type =Process_Queue()
        __task.queue_type = Thread_Queue()
        # __task.queue_type = Async_Queue()
        __task.value = []

        # Initialize and run ocean-simple-executor
        # __exe = SimpleExecutor(mode=RunningMode.Parallel, executors=cls.__Executor_Number)
        __exe = SimpleExecutor(mode=RunningMode.Concurrent,
                               executors=cls.__Executor_Number)
        # __exe = SimpleExecutor(mode=RunningMode.GreenThread, executors=cls.__Executor_Number)
        # __exe = SimpleExecutor(mode=RunningMode.Asynchronous, executors=cls.__Executor_Number)

        # # # # Run without arguments
        __exe.map_with_function(functions=[
            cls.__producer_p.send_process, cls.__consumer_p.receive_process
        ],
                                queue_tasks=__task,
                                features=__condition)
예제 #4
0
    def main_run(self):
        # # # # Initial Executor object
        __executor = SimpleExecutor(mode=RunningMode.Asynchronous, executors=self.__Executor_Number)

        # # # # Running the Executor
        # # # # Asynchronous version of generally running
        __executor.run(
            function=self.__example.async_target_function,
            # function=self.__example.target_function,
            args=("index_1", "index_2.2"))

        # # # # Asynchronous version of generally running which will raise exception
        # __executor.run(
        #     function=self.__example.async_target_fail_function,
        #     args=("index_1", "index_2.2"))

        # # # # Map running which will raise exception
        # __executor.map(
        #     function=self.__example.async_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.async_target_function, self.__example.async_target_function],
        #     args_iter=[("index_1", "index_2.2"), ("index_3",), (1, 2, 3)])

        # # # # Get result
        __result = __executor.result()
        print("Result: ", __result)
예제 #5
0
    def main_run(self):
        # # # # Initial Executor object
        __executor = SimpleExecutor(mode=RunningMode.Asynchronous, executors=self.__Executor_Number)

        # # # # Running the Executor
        # # # # Generally running
        __executor.run(function=self.__example.crawl_process)

        # # # # Get result
        __result = __executor.result()
        print("Result: ", __result)
예제 #6
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)

        # # # # Running the Executor
        # # # # Generally running
        __executor.run(function=self.__example.crawl_process)

        # # # # Get result
        __result = __executor.result()
        print("Result: ", __result)
예제 #7
0
    def main_run(cls):
        # Initialize Event object
        __event = EventFactory()

        # # # # Initialize and run ocean-simple-executor
        # __exe = SimpleExecutor(mode=RunningMode.Parallel, executors=cls.__Executor_Number)
        __exe = SimpleExecutor(mode=RunningMode.Concurrent, executors=cls.__Executor_Number)
        # __exe = SimpleExecutor(mode=RunningMode.GreenThread, executors=cls.__Executor_Number)
        # __exe = SimpleExecutor(mode=RunningMode.Asynchronous, executors=cls.__Executor_Number)

        # # # # Run without arguments
        __exe.map_with_function(
            functions=[cls.__wakeup_p.wake_other_process, cls.__sleep_p.go_sleep],
            features=__event)
예제 #8
0
    def main_run(cls):
        # Initialize Event object
        __event = EventFactory()

        # # # # Initialize and run ocean-simple-executor
        __exe = SimpleExecutor(mode=RunningMode.Asynchronous,
                               executors=cls.__Executor_Number)

        # # # # Run without arguments
        # # # # Asynchronous version of running without arguments
        __exe.map_with_function(functions=[
            cls.__wakeup_p.async_wake_other_process,
            cls.__sleep_p.async_go_sleep
        ],
                                features=__event)
예제 #9
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)
    def main_run(cls):
        # Initialize Condition object
        __condition = ConditionFactory()

        # Initialize Queue object
        __task = QueueTask()
        __task.name = "test_queue"
        __task.queue_type = Async_Queue()
        __task.value = []

        # Initialize and run ocean-simple-executor
        __exe = SimpleExecutor(mode=RunningMode.Asynchronous, executors=cls.__Executor_Number)

        # # # # Run without arguments
        # # # # Asynchronous version of running without arguments
        __exe.map_with_function(
            functions=[cls.__producer_p.async_send_process, cls.__consumer_p.async_receive_process],
            queue_tasks=__task,
            features=__condition)
예제 #11
0
def executor_as_thread():
    return SimpleExecutor(mode=RunningMode.Concurrent, executors=_Worker_Size)
예제 #12
0
def executor_as_process():
    return SimpleExecutor(mode=RunningMode.Parallel, executors=_Worker_Size)
예제 #13
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 SimpleExecutor, RunningMode


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


executor = SimpleExecutor(mode=RunningMode.Parallel, executors=3)
executor.run(function=function,
             args={"index": f"test_{random.randrange(1, 10)}"})
result = executor.result()
print(f"This is final result: {result}")
예제 #14
0
_Worker_Size = 7
_Semaphore_Value = 2


def target_function_with_bsmp() -> str:
    return retry_success_with_bsmp()


@retry.function
@RunWith.Bounded_Semaphore
def retry_success_with_bsmp() -> str:
    print("Running function ...")
    _worker_name = context.get_current_worker_name()
    return f"{_worker_name} Running Result"


if __name__ == '__main__':

    set_mode(RunningMode.Parallel)

    _bsmp_factory = BoundedSemaphoreFactory(value=_Semaphore_Value)
    _sexor = SimpleExecutor(executors=_Worker_Size)
    _sexor.run(function=target_function_with_bsmp, features=_bsmp_factory)
    _result = _sexor.result()

    for _r in _result:
        print("++++++++++++++++++++++++++++")
        print(f"worker_name: {_r.worker_name}")
        print(f"data: {_r.data}")
        print(f"exception: {_r.exception}")
import pathlib
import time
import sys

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

from multirunnable import SimpleExecutor, RunningMode
from multirunnable.api import RunWith
from multirunnable.factory import LockFactory

Thread_Number = 5


@RunWith.Lock
def lock_function():
    print("This is testing process with Lock and sleep for 3 seconds.")
    time.sleep(3)


if __name__ == '__main__':
    # Initialize Lock object
    __lock = LockFactory()

    # # # # Initial Executor object
    __executor = SimpleExecutor(mode=RunningMode.Concurrent,
                                executors=Thread_Number)

    # # # # Running the Executor
    __executor.run(function=lock_function, features=__lock)
예제 #16
0
def executor_as_green_thread():
    return SimpleExecutor(mode=RunningMode.GreenThread, executors=_Worker_Size)
예제 #17
0
def executor_as_asynchronous():
    return SimpleExecutor(mode=RunningMode.Asynchronous,
                          executors=_Worker_Size)
예제 #18
0
def instantiate_executor(request) -> SimpleExecutor:
    set_mode(mode=request.param)
    _executor = SimpleExecutor(mode=request.param, executors=_Worker_Size)
    initial_lock()
    return _executor