Skip to content

Commit

Permalink
adding script to send async requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduard0803 committed Oct 17, 2024
1 parent 39d8b86 commit 45449e0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions arequest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from time import perf_counter
import asyncio

import aiohttp


async def fetch(s, url):
async with s.get("http://localhost:8000") as r:
return await r.text()

async def fetch_all(s, urls):
tasks = []
for url in urls:
task = asyncio.create_task(fetch(s, url))
tasks.append(task)
return await asyncio.gather(*tasks)

async def main():
urls = range(1, 10 * 1000)
async with aiohttp.ClientSession() as s:
html = await fetch_all(s, urls)
print(html)

if __name__ == "__main__":
start = perf_counter()
asyncio.run(main())
end = perf_counter()
print(f"time: {end-start}")

0 comments on commit 45449e0

Please sign in to comment.