小编And*_*ani的帖子

Python asyncio 和 aiohttp 在 150 多个请求后变慢

我正在使用 asyncio 和 aiohttp 来制作异步抓取工具。出于某种原因,在我达到 150+ 请求后,它开始变慢。第一个异步在我获得链接的地方运行良好。第二个是我遇到缓慢发生的问题的地方。就像在 200 之后,一个请求需要 1 分钟。知道为什么吗?我是否错误地使用了 Asyncio 或 aiohttp?编辑:我在 7gb ram 上运行这个本地,所以我不认为我内存不足。

import aiohttp
import asyncio
import async_timeout
import re
from lxml import html
import timeit
from os import makedirs,chmod


basepath = ""
start = timeit.default_timer()
novel = ""
novel = re.sub(r"[^a-zA-Z0-9 ]+/", "", novel)
novel = re.sub(r" ", "-", novel)

novel_url = {}
@asyncio.coroutine
def get(*args, **kwargs):
    response = yield from aiohttp.request('GET', *args, **kwargs)
    return (yield from response.text())

def scrape_links(page):
    url = html.fromstring(page)
    links …
Run Code Online (Sandbox Code Playgroud)

python performance python-asyncio aiohttp

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

标签 统计

aiohttp ×1

performance ×1

python ×1

python-asyncio ×1