Created
June 20, 2022 22:40
-
-
Save theelous3/d03c047c1591c1316d95a08cbb1a4d1f 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 | |
from random import randint | |
from httpx import AsyncClient | |
async_client = AsyncClient() | |
async def handler(handler_id): | |
6452 ** randint(1, 10) | |
print(handler_id, 1) | |
await async_client.get("https://example.com") | |
print(handler_id, 2) | |
await asyncio.sleep(randint(0, 3)) | |
print(handler_id, 3) | |
r = await asyncio.gather(*[async_client.get("https://example.com") for _ in range(randint(1, 5))]) | |
print(handler_id, 4) | |
async def main(): | |
handlers = [handler(x) for x in range(1, 6)] | |
await asyncio.gather(*handlers) | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment