forked from bedroombuilds/python2rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasync.py
More file actions
28 lines (20 loc) · 658 Bytes
/
async.py
File metadata and controls
28 lines (20 loc) · 658 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
import aiohttp
import asyncio
import time
from person import URL, summary
async def fetch_person(session, url):
async with session.get(url) as resp:
json = await resp.json()
return json
async def main():
async with aiohttp.ClientSession() as session:
tasks = []
for _ in range(50):
tasks.append(asyncio.ensure_future(fetch_person(session, URL)))
all_data = await asyncio.gather(*tasks)
for data in all_data:
print(summary(data))
if __name__ == "__main__":
start_time = time.time()
asyncio.run(main())
print("--- %s seconds ---" % (time.time() - start_time))