Skip to content

Commit e1f01b5

Browse files
committed
[OMCSessionZMQ] use specific exceptions instead of generic Exception where possible
1 parent 3ce750d commit e1f01b5

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

OMPython/OMCSession.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,10 @@ def __del__(self):
373373
self._omc_log_file.close()
374374
try:
375375
self._omc_process.wait(timeout=2.0)
376-
except Exception:
376+
except subprocess.TimeoutExpired:
377377
if self._omc_process:
378-
logger.warning("OMC did not exit after being sent the quit() command; killing the process with pid=%s", self._omc_process.pid)
378+
logger.warning("OMC did not exit after being sent the quit() command; "
379+
"killing the process with pid=%s", self._omc_process.pid)
379380
self._omc_process.kill()
380381
self._omc_process.wait()
381382

@@ -405,14 +406,14 @@ def _start_omc_process(self, timeout):
405406
try:
406407
with open(self._dockerCidFile, "r") as fin:
407408
self._dockerCid = fin.read().strip()
408-
except Exception:
409+
except IOError:
409410
pass
410411
if self._dockerCid:
411412
break
412413
time.sleep(timeout / 40.0)
413414
try:
414415
os.remove(self._dockerCidFile)
415-
except Exception:
416+
except FileNotFoundError:
416417
pass
417418
if self._dockerCid is None:
418419
logger.error("Docker did not start. Log-file says:\n%s" % (open(self._omc_log_file.name).read()))
@@ -520,9 +521,10 @@ def _connect_to_omc(self, timeout):
520521
while True:
521522
if self._dockerCid:
522523
try:
523-
self._port = subprocess.check_output(["docker", "exec", self._dockerCid, "cat", self._port_file], stderr=subprocess.DEVNULL).decode().strip()
524+
self._port = subprocess.check_output(["docker", "exec", self._dockerCid, "cat", self._port_file],
525+
stderr=subprocess.DEVNULL).decode().strip()
524526
break
525-
except Exception:
527+
except subprocess.CalledProcessError:
526528
pass
527529
else:
528530
if os.path.isfile(self._port_file):

0 commit comments

Comments
 (0)