Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from time import time
- import aiohttp
- import asyncio
- semaphore = asyncio.Semaphore(50)
- q = []
- async def get_reputaion(steamid):
- async with aiohttp.ClientSession() as s:
- res = await s.post(f'http://steamrep.com/api/beta4/reputation/{steamid}/?json=1')
- data = await res.json()
- status = data['steamrep']['reputation']['summary']
- q.append(status)
- async def semaphored_coro(coro):
- async with semaphore:
- return await coro
- async def main():
- # create 1k tasks
- tasks = [asyncio.create_task(semaphored_coro(get_reputaion('76561198047255985'))) for _ in range(1000)]
- await asyncio.gather(*tasks)
- if __name__ == '__main__':
- start = time()
- loop = asyncio.get_event_loop()
- try:
- loop.run_until_complete(main())
- finally:
- loop.run_until_complete(loop.shutdown_asyncgens())
- loop.close()
- end = time()
- print(f'time = {end - start}')
- print(q.count('none'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement