Skip to content

Instantly share code, notes, and snippets.

@theelous3
Created June 20, 2022 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theelous3/d03c047c1591c1316d95a08cbb1a4d1f to your computer and use it in GitHub Desktop.
Save theelous3/d03c047c1591c1316d95a08cbb1a4d1f to your computer and use it in GitHub Desktop.
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