From e4aa2149f7e8cdca6ef7269c13d88a7376331819 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Wed, 21 Sep 2022 11:35:42 +0200 Subject: [PATCH] phytron: fix warning on repeated comm. error log only a warning when several retries ware successful Change-Id: I2f1dfba920b0841914da82229820bcdd4b97c6e9 --- secop_psi/phytron.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/secop_psi/phytron.py b/secop_psi/phytron.py index 614814d..66899e5 100644 --- a/secop_psi/phytron.py +++ b/secop_psi/phytron.py @@ -35,7 +35,9 @@ class PhytronIO(StringIO): identification = [('0IVR', 'MCC Minilog .*')] def communicate(self, command): - for ntry in range(5, 0, -1): + ntry = 5 + warn = None + for itry in range(ntry): try: _, _, reply = super().communicate('\x02' + command).partition('\x02') if reply[0] == '\x06': # ACK @@ -43,9 +45,12 @@ class PhytronIO(StringIO): raise CommunicationFailedError('missing ACK %r (cmd: %r)' % (reply, command)) except Exception as e: - if ntry == 1: + if itry < ntry - 1: + warn = e + else: raise - self.log.warning('%s - retry', e) + if warn: + self.log.warning('needed %d retries after %r', itry, warn) return reply[1:]