Advertisement
Guest User

123

a guest
Aug 19th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. from time import time
  2.  
  3. import aiohttp
  4. import asyncio
  5.  
  6. semaphore = asyncio.Semaphore(50)
  7. q = []
  8.  
  9.  
  10. async def get_reputaion(steamid):
  11. async with aiohttp.ClientSession() as s:
  12. res = await s.post(f'http://steamrep.com/api/beta4/reputation/{steamid}/?json=1')
  13. data = await res.json()
  14. status = data['steamrep']['reputation']['summary']
  15. q.append(status)
  16.  
  17.  
  18. async def semaphored_coro(coro):
  19. async with semaphore:
  20. return await coro
  21.  
  22.  
  23. async def main():
  24. # create 1k tasks
  25. tasks = [asyncio.create_task(semaphored_coro(get_reputaion('76561198047255985'))) for _ in range(1000)]
  26. await asyncio.gather(*tasks)
  27.  
  28.  
  29. if __name__ == '__main__':
  30. start = time()
  31. loop = asyncio.get_event_loop()
  32. try:
  33. loop.run_until_complete(main())
  34. finally:
  35. loop.run_until_complete(loop.shutdown_asyncgens())
  36. loop.close()
  37. end = time()
  38. print(f'time = {end - start}')
  39. print(q.count('none'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement