refactor stop
This commit is contained in:
parent
f567aca532
commit
20af1396b9
1 changed files with 7 additions and 7 deletions
|
@ -67,6 +67,9 @@ class ClientSession(BaseClientSession):
|
||||||
await asyncio.wait_for(self.trigger_urgent_reconnect.wait(), timeout=retry_delay)
|
await asyncio.wait_for(self.trigger_urgent_reconnect.wait(), timeout=retry_delay)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
pass
|
pass
|
||||||
|
except asyncio.CancelledError as exception:
|
||||||
|
self.connection_lost(exception)
|
||||||
|
raise exception
|
||||||
finally:
|
finally:
|
||||||
self.trigger_urgent_reconnect.clear()
|
self.trigger_urgent_reconnect.clear()
|
||||||
|
|
||||||
|
@ -133,7 +136,6 @@ class BaseNetwork:
|
||||||
|
|
||||||
async def stop(self):
|
async def stop(self):
|
||||||
self.running = False
|
self.running = False
|
||||||
if self.session_pool:
|
|
||||||
self.session_pool.stop()
|
self.session_pool.stop()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -149,13 +151,13 @@ class BaseNetwork:
|
||||||
raise ConnectionError("Attempting to send rpc request when connection is not available.")
|
raise ConnectionError("Attempting to send rpc request when connection is not available.")
|
||||||
|
|
||||||
async def retriable_call(self, function, *args, **kwargs):
|
async def retriable_call(self, function, *args, **kwargs):
|
||||||
while True:
|
while self.running:
|
||||||
try:
|
try:
|
||||||
return await function(*args, **kwargs)
|
return await function(*args, **kwargs)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
log.warning("Wallet server call timed out, retrying.")
|
log.warning("Wallet server call timed out, retrying.")
|
||||||
except ConnectionError:
|
except ConnectionError:
|
||||||
if not self.is_connected:
|
if not self.is_connected and self.running:
|
||||||
log.warning("Wallet server unavailable, waiting for it to come back and retry.")
|
log.warning("Wallet server unavailable, waiting for it to come back and retry.")
|
||||||
await self.on_connected.first
|
await self.on_connected.first
|
||||||
|
|
||||||
|
@ -226,10 +228,8 @@ class SessionPool:
|
||||||
self.ensure_connections()
|
self.ensure_connections()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
for session, task in self.sessions.items():
|
for task in self.sessions.values():
|
||||||
task.cancel()
|
task.cancel()
|
||||||
session.connection_lost(asyncio.CancelledError())
|
|
||||||
session.abort()
|
|
||||||
self.sessions.clear()
|
self.sessions.clear()
|
||||||
|
|
||||||
def ensure_connections(self):
|
def ensure_connections(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue