I use aiohttp
to request the url. Most of the time it runs normally, but sometimes it stops without raising any exception.
As you can see in the code, I catch all the exceptions, but when it stops no log of exceptions is printed.
The logs look like:
get_live_league_games: while True
try
yield from aiohttp.request
but the 'res = yield from r.json()
' does not print, it stops and does not throw any exceptions.
while True:
print('get_live_league_games: while True')
start = time.clock()
try:
print('try')
r = yield from aiohttp.request('GET',url)
print('yield from aiohttp.request')
res = yield from r.json()
print('res = yield from r.json()')
except aiohttp.errors.DisconnectedError as e:
logging.warning('get_live_league_games:',e)
yield from asyncio.sleep(10)
continue
except aiohttp.errors.ClientError as e:
logging.warning('get_live_league_games:',e)
yield from asyncio.sleep(10)
continue
except aiohttp.errors.HttpProcessingError as e:
logging.warning('get_live_league_games:',e)
yield from asyncio.sleep(10)
continue
except Exception as e:
logging.warning('get_live_league_games,Exception:',e)
yield from asyncio.sleep(10)
continue
print('request internet time : ', time.clock()-start)
yield from asyncio.sleep(10)
That may happen due internet nature -- connection may 'hang' for very long period before disconnection error raises.
That's why you usually need timeout for client http operations.
I suggest wrapping aiohttp.request()
call into asyncio.wait_for
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With