16 lines
396 B
Python
16 lines
396 B
Python
import aiohttp
|
|
import asyncio
|
|
|
|
from asyncio_throttle.throttler import Throttler
|
|
|
|
throttler = Throttler(rate_limit=500, period=60) # 500 requests per minute
|
|
|
|
|
|
async def worker(throttler, session):
|
|
while True:
|
|
async with throttler:
|
|
async with session.get("http://example.com") as resp:
|
|
do_some_job_with(await resp.text())
|
|
|
|
await asyncio.sleep(0.05)
|