Skip to content

Commit 9b2d75b

Browse files
committed
[ModelicaSystem/ModelicaSystemDoE] improve session handling
* add ModelicaSystem.session() - returns _getconn * add ModelicaSystemDoE.session() - returns _mod.session() reasoning: * do not access private variables of a class * limit chain access to (sub)data
1 parent 2a39752 commit 9b2d75b

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,12 @@ def __init__(
439439
if build:
440440
self.buildModel(variableFilter)
441441

442+
def session(self) -> OMCSessionZMQ:
443+
"""
444+
Return the OMC session used for this class.
445+
"""
446+
return self._getconn
447+
442448
def setCommandLineOptions(self, commandLineOptions: str):
443449
"""
444450
Set the provided command line option via OMC setCommandLineOptions().
@@ -1908,9 +1914,9 @@ def __init__(
19081914
self._timeout = timeout
19091915

19101916
if resultpath is not None:
1911-
self._resultpath = self._mod._getconn.omcpath(resultpath)
1917+
self._resultpath = self.session().omcpath(resultpath)
19121918
else:
1913-
self._resultpath = self._mod._getconn.omcpath_tempdir()
1919+
self._resultpath = self.session().omcpath_tempdir()
19141920

19151921
if not self._resultpath.is_dir():
19161922
raise ModelicaSystemError(f"Resultpath {self._resultpath.as_posix()} does not exists!")
@@ -1923,6 +1929,12 @@ def __init__(
19231929
self._sim_dict: Optional[dict[str, dict[str, Any]]] = None
19241930
self._sim_task_query: queue.Queue = queue.Queue()
19251931

1932+
def session(self) -> OMCSessionZMQ:
1933+
"""
1934+
Return the OMC session used for this class.
1935+
"""
1936+
return self._mod.session()
1937+
19261938
def prepare(self) -> int:
19271939
"""
19281940
Prepare the DoE by evaluating the parameters. Each structural parameter requires a new instance of
@@ -2064,7 +2076,7 @@ def worker(worker_id, task_queue):
20642076
raise ModelicaSystemError("Missing simulation definition!")
20652077

20662078
resultfile = mscmd.arg_get(key='r')
2067-
resultpath = self._mod._getconn.omcpath(resultfile)
2079+
resultpath = self.session().omcpath(resultfile)
20682080

20692081
logger.info(f"[Worker {worker_id}] Performing task: {resultpath.name}")
20702082

0 commit comments

Comments
 (0)