Add timeout handling to network poll loop

kivy_mainline_and_py3.8
Tyler Goodlet 2018-04-02 14:51:38 -04:00
parent 01cfbbdd64
commit e246823f2d
1 changed files with 5 additions and 1 deletions

View File

@ -51,7 +51,11 @@ async def wait_for_network(get_quotes, sleep=1):
""" """
while True: while True:
try: try:
with trio.move_on_after(1) as cancel_scope:
return await get_quotes() return await get_quotes()
if cancel_scope.cancelled_caught:
log.warn("Quote query timed out")
continue
except socket.gaierror: except socket.gaierror:
log.warn(f"Network is down waiting for reestablishment...") log.warn(f"Network is down waiting for reestablishment...")
await trio.sleep(sleep) await trio.sleep(sleep)