Commit 48d735f3 authored by Stanislav Bohm's avatar Stanislav Bohm
Browse files

Client retries to connect server

parent ac0462d1
......@@ -21,9 +21,20 @@ class Client:
def _connect(self, hostname, port):
async def connect():
connection = abrpc.Connection(
await asyncio.open_connection(hostname, port=port)
)
max_tries = 20
i = 0
while True:
try:
connection = abrpc.Connection(
await asyncio.open_connection(hostname, port=port)
)
break
except ConnectionError as e:
i += 1
logger.error("Could not connect to server (attempt [%s,%s])", i, max_tries)
if i == max_tries:
raise e
await asyncio.sleep(1.0)
asyncio.ensure_future(connection.serve())
logger.info("Connection to server established")
return connection
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment