• XSS.stack #1 – первый литературный журнал от юзеров форума

[Script] Concurrent requests with Asyncio

P_path

HDD-drive
Пользователь
Регистрация
25.11.2022
Сообщения
40
Реакции
12
Some code I made to test privoxy performance with tor, it's clunky but did the job, someone may find it useful since I didn't now about asyncio before and know nothing on threading or multiprocessing 😂

Python:
import asyncio
from aiohttp import ClientSession

http_proxy = "http://"

async def rqes(ses, url, number):
    async with ses.get(url, proxy=http_proxy) as response:
        response = await response.read()
        print(f"{number} {response}")
        return response

async def main(url):
    async with ClientSession() as session:
        tasks = []
        for number in range(100):
            tasks.append(asyncio.ensure_future(rqes(session, url, number)))

        tt = await asyncio.gather(*tasks)
        for task in tt:
            print(task)

asyncio.run(main("http://httpbin.org/ip"))
 


Напишите ответ...
  • Вставить:
Прикрепить файлы
Верх