Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from typing import Union
- import time
- import aiohttp
- import asyncio
- import async_timeout
- async def send_post(url: str, post_data: Union[str, bytes, dict], timeout=60) -> bool:
- with async_timeout.timeout(timeout):
- async with aiohttp.ClientSession() as session:
- async with session.post(url, data=post_data) as response:
- if response.status == 200:
- return True
- return False
- list_requests = [
- # URL, POSTDATA
- ('http://httpbin.org/post', {'a': 1, 'b': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ('http://httpbin.org/post', {'c': 1, 'd': 2}),
- ]
- list_tasks = list()
- for args in list_requests:
- list_tasks.append(send_post(*args))
- start_time = time.time()
- loop = asyncio.get_event_loop()
- loop.run_until_complete(asyncio.wait(list_tasks))
- print('end time: {}'.format(time.time() - start_time))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement