diff options
Diffstat (limited to 'mmi2grpc/__init__.py')
-rw-r--r-- | mmi2grpc/__init__.py | 19 |
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, |