forked from bendeez/AsyncLoop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
27 lines (22 loc) · 803 Bytes
/
main.py
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
from AsyncLoop import EventLoop, AsyncClient
async def scrape_other_website():
results = await EventLoop.gather(*[AsyncClient.request("https://youtube.com") for _ in range(10)])
return results
async def scrape_website(url):
first_result = await scrape_other_website()
print(first_result)
second_result = await EventLoop.gather(*[AsyncClient.request(url) for _ in range(20)])
return second_result
async def main():
url = "https://github.com/"
task_1 = EventLoop.create_task(scrape_website(url))
print(task_1)
task_2 = EventLoop.create_task(scrape_other_website())
print(task_2)
result = await EventLoop.gather(task_1,task_2)
print(result)
import time
start = time.time()
EventLoop.run(main(), max_clients=100)
end = time.time()
print(end - start)