-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtraffic_generator.py
More file actions
executable file
·32 lines (26 loc) · 1011 Bytes
/
Copy pathtraffic_generator.py
File metadata and controls
executable file
·32 lines (26 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import asyncio
import aiohttp
import time
async def get_notes(url):
while True:
try:
async with aiohttp.ClientSession() as session:
response = await session.get(url)
if response.status == 200:
print("GET request successful")
# Process the response data if needed
print(await response.json())
else:
print("GET request failed with status code:", response.status)
except aiohttp.ClientError as e:
print("GET request failed:", e)
await asyncio.sleep(2) # Delay for 5 seconds before sending the next request
async def main():
urls = ["http://localhost:8001/notes/", "http://localhost:8001/notes/32"] # Replace with your desired URLs
tasks = []
for url in urls:
task = asyncio.create_task(get_notes(url))
tasks.append(task)
await asyncio.gather(*tasks)
# Run the main function
asyncio.run(main())