Tôi sử dụng aiohttp
để yêu cầu url. Hầu hết thời gian nó chạy bình thường, nhưng đôi khi nó dừng lại mà không gây bất kỳ ngoại lệ nào.Yêu cầu aiohttp của Python đã dừng nhưng không có ngoại lệ
Như bạn có thể thấy trong mã, tôi bắt tất cả ngoại lệ, nhưng khi không dừng nhật ký ngoại lệ được in.
Các bản ghi như sau:
get_live_league_games: while True
try
yield from aiohttp.request
nhưng 'res = yield from r.json()
' không in, nó dừng lại và không ném bất kỳ trường hợp ngoại lệ.
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)
không liên quan: mã rất lặp đi lặp lại. Bạn có thể thả tất cả các trình xử lý ngoại lệ ngoại trừ trình xử lý cuối cùng. – jfs