Skip to content

Commit

Permalink
Merge pull request #35 from radonnachie/patch-1
Browse files Browse the repository at this point in the history
katcprequest retry loop (untested initial draft)
  • Loading branch information
wnew committed May 10, 2022
2 parents 18711da + f872b3c commit 4bfd8ec
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/transport_katcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def disconnect(self):
self.logger.info('%s: disconnected' % self.host)

def katcprequest(self, name, request_timeout=-1.0, require_ok=True,
request_args=()):
request_args=(), max_retries=3, retry_delay_s=0.5):
"""
Make a blocking request to the KATCP server and check the result.
Raise an error if the reply indicates a request failure.
Expand All @@ -244,13 +244,23 @@ def katcprequest(self, name, request_timeout=-1.0, require_ok=True,
must time out
:param require_ok: will we raise an exception on a response != ok
:param request_args: request arguments.
:param max_retries: maximum number of retries in the case of errors (3).
:param retry_delay_s: the delay between retries in the case of errors (0.5 seconds).
:return: tuple of reply and informs
"""
# TODO raise sensible errors
if request_timeout == -1:
request_timeout = self._timeout
request = katcp.Message.request(name, *request_args)
reply, informs = self.blocking_request(request, timeout=request_timeout)
reply = None
retries = 0

while retries == 0 or (require_ok and retries < max_retries and (reply.arguments[0] != katcp.Message.OK)):
if retries > 0:
time.sleep(retry_delay_s)
reply, informs = self.blocking_request(request, timeout=request_timeout)
retries += 1

if (reply.arguments[0] != katcp.Message.OK) and require_ok:
if reply.arguments[0] == katcp.Message.FAIL:
raise KatcpRequestFail(
Expand Down

0 comments on commit 4bfd8ec

Please sign in to comment.