5
tqdm
進捗バーを統合して、aiohttp
で生成されたPOST要求をPython 3.5で監視しようとしています。私は進行中のバーを持っていますが、as_completed()
を使って結果を集めるように見えません。ポインタは感謝して受け取りました。私が見つけたasyncio aiohttp tqdmの進行状況
例としては、Pythonと互換性がありません。次のパターンを、使用することをお勧め3.5 async def
定義:
for f in tqdm.tqdm(asyncio.as_completed(tasks), total=len(coros)):
yield from f
ワーキング(いえ部品に編集済み)プログレスバーのない非同期コード:
def async_classify(records):
async def fetch(session, name, sequence):
url = 'https://app.example.com/api/v0/search'
payload = {'sequence': str(sequence)}
async with session.post(url, data=payload) as response:
return name, await response.json()
async def loop():
auth = aiohttp.BasicAuth(api_key)
conn = aiohttp.TCPConnector(limit=100)
with aiohttp.ClientSession(auth=auth, connector=conn) as session:
tasks = [fetch(session, record.id, record.seq) for record in records]
responses = await asyncio.gather(*tasks)
return OrderedDict(responses)
これは修正に失敗しましたloop()
:
async def loop():
auth = aiohttp.BasicAuth(api_key)
conn = aiohttp.TCPConnector(limit=100)
with aiohttp.ClientSession(auth=auth, connector=conn) as session:
tasks = [fetch(session, record.id, record.seq) for record in records]
for f in tqdm.tqdm(asyncio.as_completed(tasks), total=len(tasks)):
await f
responses = await asyncio.gather(f)
print(responses)
ありがとう:) –
@ j-f-sebastienラブリー!知らせてくれてありがとうございます –