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)
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)
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)
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)
def test_map_with_function(self, instantiate_executor: SimpleExecutor): TestSimpleExecutor._initial() initial_rlock() _function_a_flag = Global_Manager.Value(int, 0) _function_b_flag = Global_Manager.Value(int, 0) _workers_ids = Global_Manager.list() _current_workers = Global_Manager.list() _done_timestamp = Global_Manager.list() def _target_a(*args): nonlocal _function_a_flag, _workers_ids, _current_workers, _done_timestamp _function_a_flag.value += 1 _ident = _get_worker_id() _current_worker = _get_current_worker() _workers_ids.append(_ident) _current_workers.append(str(_current_worker)) _done_timestamp.append(int(time.time())) _sleep_time() def _target_b(*args): nonlocal _function_b_flag, _workers_ids, _current_workers, _done_timestamp _function_b_flag.value += 1 _ident = _get_worker_id() _current_worker = _get_current_worker() _workers_ids.append(_ident) _current_workers.append(str(_current_worker)) _done_timestamp.append(int(time.time())) _sleep_time() _functions = [_target_a, _target_b] instantiate_executor.map_with_function(functions=_functions) _results = instantiate_executor.result() assert len(_results) == len(_functions), "" TestSimpleExecutor._chk_map_with_function(_functions, _function_a_flag, _function_b_flag, _workers_ids, _current_workers, _done_timestamp)
def test_map_with_function(self, executor_as_thread: SimpleExecutor): TestSimpleExecutor._initial() _function_a_flag = 0 _function_b_flag = 0 _thread_ids = [] _threads = [] _done_timestamp = [] def _target_a(): # with _Thread_RLock: nonlocal _function_a_flag _function_a_flag += 1 _thread_ids.append(threading.get_ident()) _threads.append(threading.current_thread()) _done_timestamp.append(int(time.time())) time.sleep(Test_Function_Sleep_Time) def _target_b(): # with _Thread_RLock: nonlocal _function_b_flag _function_b_flag += 1 _thread_ids.append(threading.get_ident()) _threads.append(threading.current_thread()) _done_timestamp.append(int(time.time())) time.sleep(Test_Function_Sleep_Time) _functions = [_target_a, _target_b] executor_as_thread.map_with_function(functions=_functions) # Do some checking # 1. The amount of workers should be the same with the amount of functions. # 3. The amount of thread IDs should be the same with the amount of functions. # 2. The done-timestamp should be very close. TestSimpleExecutor._chk_map_with_function(_functions, _function_a_flag, _function_b_flag, _thread_ids, _threads, _done_timestamp)