Skip to content

Commit

Permalink
Merge pull request #9 from george0st/changes
Browse files Browse the repository at this point in the history
Finishing init call
  • Loading branch information
george0st authored Oct 12, 2023
2 parents 46f6bc0 + b69f610 commit 5d71b96
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 28 deletions.
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from qgate_perf.parallel_executor import ParallelExecutor, InitCallSetting
from qgate_perf.parallel_executor import ParallelExecutor
from qgate_perf.parallel_probe import ParallelProbe
from qgate_perf.run_setup import RunSetup
from qgate_perf.run_return import RunReturn
Expand Down
31 changes: 10 additions & 21 deletions qgate_perf/parallel_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@

from contextlib import suppress


class InitCallSetting:
Off = 0
EachBundle = 1
EachExecutor = 2

@staticmethod
def all():
return InitCallSetting.EachBundle + InitCallSetting.EachExecutor

def _executor_wrapper(func, run_return: RunReturn, run_setup: RunSetup):
"""
Lightweight internal wrapper for exception handling in executor
Expand Down Expand Up @@ -60,21 +50,21 @@ def __init__(self,
label = None,
detail_output = True,
output_file = None,
init_call: InitCallSetting = InitCallSetting.Off):
init_each_bulk = False):
""" Setting of execution
:param func: function for parallel run
:param label: text label for parallel run
:param detail_output: provide details output from executors
:param output_file: output to the file, defualt is without file
:param init_call: init call before exection
:param init_each_bulk: call 'init_run' before each bulk (useful e.g. change amount of columns in target)
"""
self._func = func
self._func_wrapper = _executor_wrapper
self._detail_output = detail_output
self._label = label
self._output_file = output_file
self._init_call = init_call
self._init_each_bulk = init_each_bulk

# Technical point, how to close Process
# in python >= 3.7 Close() as soft closing
Expand Down Expand Up @@ -287,10 +277,10 @@ def _executeCore(self, run_setup: RunSetup, return_dict, processes=2, threads=2)
p.terminate() # hard close

def run_bulk_executor(self,
bulk_list= BundleHelper.ROW_1_COL_10_100,
executor_list= ExecutorHelper.PROCESS_2_8_THREAD_1_4_SHORT,
run_setup: RunSetup=None,
sleep_between_bulks=0):
bulk_list= BundleHelper.ROW_1_COL_10_100,
executor_list= ExecutorHelper.PROCESS_2_8_THREAD_1_4_SHORT,
run_setup: RunSetup=None,
sleep_between_bulks=0):
""" Run cykle of bulks in cycle of sequences for function execution
:param bulk_list: list of bulks for execution in format [[rows, columns], ...]
Expand All @@ -301,6 +291,7 @@ def run_bulk_executor(self,
False - some exceptions
"""
final_state = True

for bulk in bulk_list:
run_setup.set_bulk(bulk[0], bulk[1])

Expand All @@ -325,8 +316,7 @@ def run_executor(self, executor_list= ExecutorHelper.PROCESS_2_8_THREAD_1_4_SHOR
print('Execution...')

try:
# TODO: experiment with init call
if self._init_call & InitCallSetting.EachBundle:
if self._init_each_bulk:
self.init_run(run_setup)

if self._output_file is not None:
Expand Down Expand Up @@ -372,8 +362,7 @@ def run(self, processes=2, threads=2, run_setup: RunSetup=None):
print('Execution...')

try:
# TODO: experiment with init call
if self._init_call & InitCallSetting.EachBundle:
if self._init_each_bulk:
self.init_run(run_setup)

if self._output_file is not None:
Expand Down
2 changes: 1 addition & 1 deletion qgate_perf/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# 1) we don't load dependencies by storing it in __init__.py
# 2) we can import it in setup.py for the same reason
# 3) we can import it into your module module
__version__ = '0.3.9'
__version__ = '0.4.0'
2 changes: 1 addition & 1 deletion tests/test_internal.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import unittest
import logging
from qgate_perf.parallel_executor import ParallelExecutor, InitCallSetting
from qgate_perf.parallel_executor import ParallelExecutor
from qgate_perf.parallel_probe import ParallelProbe
from qgate_perf.run_setup import RunSetup
from qgate_perf.executor_helper import ExecutorHelper
Expand Down
9 changes: 5 additions & 4 deletions tests/test_perf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import unittest
import logging
from qgate_perf.parallel_executor import ParallelExecutor, InitCallSetting
from qgate_perf.parallel_executor import ParallelExecutor
from qgate_perf.parallel_probe import ParallelProbe
from qgate_perf.run_setup import RunSetup
from qgate_perf.executor_helper import ExecutorHelper
Expand Down Expand Up @@ -165,7 +165,8 @@ def test_run_bulk_executor(self):
generator = ParallelExecutor(prf_GIL_impact,
label="GIL_impact",
detail_output=True,
output_file=path.join(self.OUTPUT_ADR, "perf_gil_impact_test.txt"))
output_file=path.join(self.OUTPUT_ADR, "perf_gil_impact_test.txt"),
init_each_bulk=True)

setup=RunSetup(duration_second=1, start_delay=0)
self.assertTrue(generator.run_bulk_executor(bulk_list=[[1,2], [1,10]],
Expand Down Expand Up @@ -216,7 +217,7 @@ def test_run_bulk_executor_initcall(self):
label="GIL_impact",
detail_output=True,
output_file=path.join(self.OUTPUT_ADR, "perf_gil_impact_test.txt"),
init_call=InitCallSetting.all())
init_each_bulk=True)

setup=RunSetup(duration_second=1, start_delay=0)
self.assertTrue(generator.run_bulk_executor(bulk_list=[[1,2], [1,10]],
Expand All @@ -237,7 +238,7 @@ def test_run_init_call(self):
label="GIL_impact",
detail_output=True,
output_file=None,
init_call=InitCallSetting.all())
init_each_bulk=True)

setup=RunSetup(duration_second=0, start_delay=0)
self.assertTrue(generator.run(1, 2, setup))
Expand Down

0 comments on commit 5d71b96

Please sign in to comment.