[Python] AttributeError: module 'select' has no attribute 'select' error ASYNCIO

Discussão em 'Python' iniciado por Stack, Fevereiro 11, 2025.

  1. Stack

    Stack Membro Participativo

    I am executing the below code on a windows pc. I read that, by default, Windows can use only 64 sockets in asyncio loop. I don't know if this is the reason for the error.

    import aiohttp
    import asyncio
    import time


    async def download_file(url):
    print(f'started downloading{url}')
    connector = aiohttp.TCPConnector(limit=60)
    async with aiohttp.clientSession(connector) as session:
    async with session.get(url) as resp:
    content = await resp.read()
    print (f'Finished download{url}')
    return content

    async def write_file(n, content):
    filename = f'async_{n}.html'
    with open(filename,'wb') as f:
    print(f'started writing{filename}')
    f.write(content)
    print(f'Finished writing{filename}')

    async def scrape_task(n,url):
    content = await download_file(url)
    await write_file(n,content)

    async def main():
    tasks = []
    for n,url in enumerate(open('urls.txt').readlines()):
    tasks.append((scrape_task(n, url)))
    await asyncio.wait(tasks)

    if __name__ == '__main__':
    t=time.perf_counter()
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())
    t2 = time.perf_counter() - t
    print(f'Total time taken: {t2:0.2f} seconds')


    I made the below changes to limit the connections to 60

    connector = aiohttp.TCPConnector(limit=60)
    async with aiohttp.clientSession(connector) as session:


    I can't figure out where I am going wrong.

    Continue reading...

Compartilhe esta Página