小编DEE*_*NGH的帖子

RuntimeError:异常被忽略:<function _ProactorBasePipeTransport

我正在使用aiohttpasynciocodetiming来发出并发请求。我最近将 Python 升级到 3.9.0 版,但出现 RuntimeError: 程序运行后事件循环已关闭。我正在尝试使用队列数据结构发出异步请求...

import asyncio
import aiohttp
from codetiming import Timer
async def task(name, work_queue):
    timer = Timer(text=f"Task {name} elapsed time: {{:.1f}}")
    async with aiohttp.ClientSession() as session:
        while not work_queue.empty():
            url = await work_queue.get()
            print(f"Task {name} getting URL: {url}")
            timer.start()
            async with session.get(url) as response:
                await response.text()
            timer.stop()
async def main():
    # Create the queue of work
    work_queue = asyncio.Queue()
    # Put some work in the queue
    for url in …
Run Code Online (Sandbox Code Playgroud)

python python-3.x async-await python-asyncio aiohttp

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