0
私はaiohttpとElementTreeを使ってWebサイトからデータを取得するPythonプログラムを持っています。以下のコードは、Raspberry PiでホストされているDiscordチャットボットのセグメントです。この関数はほとんどの場合うまく機能しますが、ボットが数日間稼働した後は、関数が暴走し始め、常にタイムアウトします。プログラムを再起動しても問題は解決されませんが、Piをリブートするだけで問題がしばらく解決されるようです。私はそれが続行することはあまりないと知っていますが、このコードセグメントでは明らかに問題がありますか、問題がどこかにあるのでしょうか?Python - aiohttpは継続的にタイムアウトを要求します
import lxml.etree as ET
import aiohttp, async_timeout
...
async with aiohttp.ClientSession() as session:
try:
with async_timeout.timeout(5):
async with session.get('https://example.com', params=params, headers=headers) as resp:
if resp.status == 200:
root = ET.fromstring(await resp.text(), ET.HTMLParser())
# Do stuff with root
else:
print("Error: {}".format(resp.response))
except Exception as e:
print("Timeout error {}".format(e))
プロセスを再起動しても問題が解決しない場合は、明らかにaiohttpの問題ではありません。 –