Created
March 2, 2020 15:17
-
-
Save victoraugustolls/01002ae218366b453e962446c9c8a274 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import httpx | |
async def do_request(client: httpx.AsyncClient): | |
try: | |
await client.get( | |
url="https://google.com", | |
) | |
except Exception as e: | |
print(f"{type(e)}: {str(e)}") | |
async def request_multiple(client: httpx.AsyncClient): | |
count = 0 | |
while True: | |
print(f"Request number: {count}") | |
await asyncio.gather( | |
do_request(client=client), | |
do_request(client=client), | |
do_request(client=client), | |
do_request(client=client), | |
do_request(client=client) | |
) | |
count += 5 | |
if __name__ == "__main__": | |
cl = httpx.AsyncClient() | |
asyncio.run(request_multiple(client=cl)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With http2 enabled: