Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[OMCSessionZMQ] use specific exceptions instead of generic Exception …
…where possible
  • Loading branch information
syntron committed Apr 29, 2025
commit e1f01b55e0f5ce53fc4567b6e9cbf263b6974a48
14 changes: 8 additions & 6 deletions OMPython/OMCSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,10 @@ def __del__(self):
self._omc_log_file.close()
try:
self._omc_process.wait(timeout=2.0)
except Exception:
except subprocess.TimeoutExpired:
if self._omc_process:
logger.warning("OMC did not exit after being sent the quit() command; killing the process with pid=%s", self._omc_process.pid)
logger.warning("OMC did not exit after being sent the quit() command; "
"killing the process with pid=%s", self._omc_process.pid)
self._omc_process.kill()
self._omc_process.wait()

Expand Down Expand Up @@ -405,14 +406,14 @@ def _start_omc_process(self, timeout):
try:
with open(self._dockerCidFile, "r") as fin:
self._dockerCid = fin.read().strip()
except Exception:
except IOError:
pass
if self._dockerCid:
break
time.sleep(timeout / 40.0)
try:
os.remove(self._dockerCidFile)
except Exception:
except FileNotFoundError:
pass
if self._dockerCid is None:
logger.error("Docker did not start. Log-file says:\n%s" % (open(self._omc_log_file.name).read()))
Expand Down Expand Up @@ -520,9 +521,10 @@ def _connect_to_omc(self, timeout):
while True:
if self._dockerCid:
try:
self._port = subprocess.check_output(["docker", "exec", self._dockerCid, "cat", self._port_file], stderr=subprocess.DEVNULL).decode().strip()
self._port = subprocess.check_output(["docker", "exec", self._dockerCid, "cat", self._port_file],
stderr=subprocess.DEVNULL).decode().strip()
break
except Exception:
except subprocess.CalledProcessError:
pass
else:
if os.path.isfile(self._port_file):
Expand Down