From b378b323b1fb402ad860922bad721e094a5d9a26 Mon Sep 17 00:00:00 2001 From: Marcin Usielski Date: Tue, 10 Oct 2023 13:21:02 +0200 Subject: [PATCH] inv --- docs/source/conf.py | 2 +- moler/device/proxy_pc2.py | 23 ++++++++++++----------- setup.py | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index c98d6380e..e2d4435e2 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -24,7 +24,7 @@ author = 'Nokia' # The short X.Y version -version = '2.14.153' +version = '2.14.154' # The full version, including alpha/beta/rc tags release = 'stable' diff --git a/moler/device/proxy_pc2.py b/moler/device/proxy_pc2.py index 75fa89c07..8715595c7 100644 --- a/moler/device/proxy_pc2.py +++ b/moler/device/proxy_pc2.py @@ -66,6 +66,7 @@ def __init__(self, sm_params, name=None, io_connection=None, io_type=None, varia :param lazy_cmds_events: set False to load all commands and events when device is initialized, set True to load commands and events when they are required for the first time. """ + self._detecting_prompt_cmd = "echo DETECTING PROMPT" self._prompt_detected = False self._use_local_unix_state = want_local_unix_state(io_type, io_connection) base_state = UNIX_LOCAL if self._use_local_unix_state else NOT_CONNECTED @@ -77,7 +78,7 @@ def __init__(self, sm_params, name=None, io_connection=None, io_type=None, varia io_constructor_kwargs=io_constructor_kwargs, sm_params=sm_params, initial_state=initial_state, lazy_cmds_events=lazy_cmds_events) - self._prompt_detector_timeout = 0.5 + self._prompt_detector_timeout = 1.9 self._after_open_prompt_detector = None self._warn_about_temporary_life_of_class() @@ -259,14 +260,14 @@ def on_connection_lost(self, connection): def _detect_after_open_prompt(self, set_callback): self.logger.info("_detect_after_open_prompt !") - self._after_open_prompt_detector = Wait4(detect_patterns=[r'^(.+)echo DETECTING PROMPT'], + self._after_open_prompt_detector = Wait4(detect_patterns=[r'^(.+){}'.format(self._detecting_prompt_cmd)], connection=self.io_connection.moler_connection, till_occurs_times=1) detector = self._after_open_prompt_detector detector.add_event_occurred_callback(callback=set_callback, callback_params={"event": detector}) detector.start(timeout=self._prompt_detector_timeout) - self.io_connection.moler_connection.sendline("echo DETECTING PROMPT") + self.io_connection.moler_connection.sendline(self._detecting_prompt_cmd) # detector.await_done(timeout=self._prompt_detector_timeout) @@ -447,18 +448,18 @@ def get_cmd(self, cmd_name, cmd_params=None, check_state=True, for_state=None): def _detect_prompt_get_cmd(self): self.logger.info("get_cmd was called but prompt has not been detected yet.") - for try_nr in range(1, 11, 1): + for try_nr in range(1, 10, 1): if self._after_open_prompt_detector is None or self._after_open_prompt_detector.running() is False: self._detect_after_open_prompt(self._set_after_open_prompt) - time.sleep(0.1) - self.logger.info("get_cmd waiting for prompt detector.") - try: - self._after_open_prompt_detector.await_done(timeout=self._prompt_detector_timeout) - except MolerException: - pass - finally: + while time.time() - self._after_open_prompt_detector.life_status.start_time < self._prompt_detector_timeout: + time.sleep(0.1) if self._prompt_detected is True: break + self.io_connection.moler_connection.sendline(self._detecting_prompt_cmd) + self.logger.info("get_cmd is canceling prompt detector.") + self._after_open_prompt_detector.cancel() + if self._prompt_detected is True: + break self._after_open_prompt_detector.cancel() self._after_open_prompt_detector = None diff --git a/setup.py b/setup.py index 35ab72ad6..38db8d31d 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setup( name='moler', # Required - version='2.14.153', # Required + version='2.14.154', # Required description='Moler is library to help in building automated tests', # Required long_description=long_description, # Optional long_description_content_type='text/markdown', # Optional (see note above)