Skip to content

Commit 2129c2b

Browse files
committed
Added timeout parameter to OMCSession and OMCSessionZMQ
1 parent 259006f commit 2129c2b

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

OMPython/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def _get_omc_path(self):
163163
raise
164164

165165
@abc.abstractmethod
166-
def _connect_to_omc(self):
166+
def _connect_to_omc(self, timeout):
167167
pass
168168

169169
# FIXME: we should have one function which interacts with OMC. Either execute OR sendExpression.
@@ -396,20 +396,20 @@ def getClassNames(self, className=None, recursive=False, qualified=False, sort=F
396396

397397
class OMCSession(OMCSessionBase):
398398

399-
def __init__(self, readonly=False):
399+
def __init__(self, readonly=False, timeout = 0.25):
400400
OMCSessionBase.__init__(self, readonly)
401401
self._create_omc_log_file("objid")
402402
# set omc executable path and args
403403
self._set_omc_command(self._get_omc_path(), "--interactive=corba +c={0}".format(self._random_string))
404404
# start up omc executable, which is waiting for the CORBA connection
405405
self._start_omc_process()
406406
# connect to the running omc instance using CORBA
407-
self._connect_to_omc()
407+
self._connect_to_omc(timeout)
408408

409409
def __del__(self):
410410
OMCSessionBase.__del__(self)
411411

412-
def _connect_to_omc(self):
412+
def _connect_to_omc(self, timeout):
413413
# add OPENMODELICAHOME\lib\python to PYTHONPATH so python can load omniORB imports
414414
sys.path.append(os.path.join(self.omhome, 'lib', 'python'))
415415
# import the skeletons for the global module
@@ -429,7 +429,7 @@ def _connect_to_omc(self):
429429
attempts = 0
430430
while True:
431431
if not os.path.isfile(self._ior_file):
432-
time.sleep(0.25)
432+
time.sleep(timeout)
433433
attempts += 1
434434
if attempts == 10:
435435
name = self._omc_log_file.name
@@ -491,20 +491,20 @@ def sendExpression(self, command, parsed=True):
491491

492492
class OMCSessionZMQ(OMCSessionBase):
493493

494-
def __init__(self, readonly=False):
494+
def __init__(self, readonly=False, timeout = 0.25):
495495
OMCSessionBase.__init__(self, readonly)
496496
self._create_omc_log_file("port")
497497
# set omc executable path and args
498498
self._set_omc_command(self._get_omc_path(), "--interactive=zmq +z={0}".format(self._random_string))
499499
# start up omc executable, which is waiting for the CORBA connection
500500
self._start_omc_process()
501501
# connect to the running omc instance using CORBA
502-
self._connect_to_omc()
502+
self._connect_to_omc(timeout)
503503

504504
def __del__(self):
505505
OMCSessionBase.__del__(self)
506506

507-
def _connect_to_omc(self):
507+
def _connect_to_omc(self, timeout):
508508
# Locating and using the IOR
509509
if sys.platform == 'win32':
510510
self._port_file = "openmodelica.port." + self._random_string
@@ -519,7 +519,7 @@ def _connect_to_omc(self):
519519
attempts = 0
520520
while True:
521521
if not os.path.isfile(self._port_file):
522-
time.sleep(0.25)
522+
time.sleep(timeout)
523523
attempts += 1
524524
if attempts == 10:
525525
name = self._omc_log_file.name

0 commit comments

Comments
 (0)