微信建网站,免费做网站软件视频,响应式企业网站模板,好的seo平台您的限制设置正常 . 你在调试时弄错了 .正如Mikhail Gerasimov在the comment指出的那样#xff0c;你将 print() 调用放在错误的位置 - 它必须在 session.get() 上下文中 .为了确保限制得到尊重#xff0c;我针对简单的日志记录服务器测试了您的代码 - 测试显示服务器接收到您…您的限制设置正常 . 你在调试时弄错了 .正如Mikhail Gerasimov在the comment指出的那样你将 print() 调用放在错误的位置 - 它必须在 session.get() 上下文中 .为了确保限制得到尊重我针对简单的日志记录服务器测试了您的代码 - 测试显示服务器接收到您在 TCPConnector 中设置的确切数量的连接 . 这是测试import asyncioimport aiohttploop asyncio.get_event_loop()class SilentServer(asyncio.Protocol):def connection_made(self, transport):# We will know when the connection is actually made:print(SERVER |, transport.get_extra_info(peername))async def get_images(url, session):chunk_size 100# This log doesnt guarantee that we will connect,# session.get() will freeze if you reach TCPConnector limitprint(fCLIENT | Making request to {url})async with session.get(urlurl) as r:while True:chunk await r.content.read(chunk_size)if not chunk:breakurls [fhttp://127.0.0.1:1337/{x} for x in range(20)]conn aiohttp.TCPConnector(limit3)session aiohttp.ClientSession(connectorconn, looploop)async def test():await loop.create_server(SilentServer, 127.0.0.1, 1337)await asyncio.gather(*(get_images(url, sessionsession) for url in urls))loop.run_until_complete(test())