aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Duarte <licorne@google.com>2022-04-19 14:35:40 +0000
committerDavid Duarte <licorne@google.com>2022-04-19 14:37:27 +0000
commit035e00aa0480de48d7bc21e5580c9da1763cfeba (patch)
treed59984621da98437d74cdc47dd83592be40ce2c7
parentbf1692bc8edf9d8b8104561bbc84ed4c86e963ff (diff)
downloadmmi2grpc-035e00aa0480de48d7bc21e5580c9da1763cfeba.tar.gz
Implement a better retry for ReadLocalAddress
Change-Id: I5d55ce4b04300850e48ba284a147e76aa4a21c44
-rw-r--r--mmi2grpc/__init__.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/mmi2grpc/__init__.py b/mmi2grpc/__init__.py
index 953d814..d710702 100644
--- a/mmi2grpc/__init__.py
+++ b/mmi2grpc/__init__.py
@@ -9,6 +9,7 @@ from .a2dp import A2DPProxy
from ._description import format_proxy
GRPC_PORT = 8999
+MAX_RETRIES = 10
class IUT:
@@ -29,14 +30,16 @@ class IUT:
@property
def address(self) -> bytes:
with grpc.insecure_channel(f'localhost:{self.port}') as channel:
- try:
- return Host(channel).ReadLocalAddress(
- wait_for_ready=True).address
- except grpc.RpcError:
- print('Retry')
- time.sleep(5)
- return Host(channel).ReadLocalAddress(
- wait_for_ready=True).address
+ tries = 0
+ while True:
+ try:
+ return Host(channel).ReadLocalAddress(wait_for_ready=True).address
+ except grpc.RpcError:
+ if tries >= MAX_RETRIES:
+ raise
+ else:
+ print('Retry', tries, 'of', MAX_RETRIES)
+ time.sleep(1)
def interact(self,
pts_address: bytes,