相关疑难解决方法(0)

使用tqdm的asyncio aiohttp进度条

我正在尝试集成一个tqdm进度条来监视aiohttp在Python 3.5中生成的POST请求.我有一个工作进度条,但似乎无法使用收集结果as_completed().指针感激不尽.

我发现的示例建议使用以下模式,该模式与Python 3.5 async def定义不兼容:

for f in tqdm.tqdm(asyncio.as_completed(tasks), total=len(coros)):
    yield from f
Run Code Online (Sandbox Code Playgroud)

在没有进度条的情况下工作(虽然部分编辑)异步代码:

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)
Run Code Online (Sandbox Code Playgroud)

这是我修改的失败尝试loop():

async def …
Run Code Online (Sandbox Code Playgroud)

progress-bar python-asyncio aiohttp python-3.5 tqdm

13
推荐指数
1
解决办法
4775
查看次数

jupyter笔记本中异步的tqdm

我在 Jupyter 笔记本中使用 tqdm 进行异步操作——我应该使用tqdm.notebook(我认为这能让我得到正确的小部件)还是tqdm.asyncio(这可能会让我得到正确的行为——items/sec calc 在我的使用中似乎关闭了) 。

tqdm

6
推荐指数
1
解决办法
721
查看次数

标签 统计

tqdm ×2

aiohttp ×1

progress-bar ×1

python-3.5 ×1

python-asyncio ×1