The asyncio and threading modules include a number of synchronization primitives. In particular, a Semaphore allows you to limit the number of concurrent tasks if you need to stay under some capacity constraint.
However, none of the existing primitives provide for rate limiting, as in making sure there are no more than n tasks started per second. I believe this Stack Overflow question shows that adding such a primitive would be useful: https://stackoverflow.com/questions/35196974/aiohttp-set-maximum-number-of-requests-per-second The asker clearly wants rate limiting, but the answers provided limit concurrency instead. I found an excellent answer by Martijn Pieters, which includes an implementation of the leaky bucket algorithm, here https://stackoverflow.com/a/45502319/1475412 The AsyncLeakyBucket is used in exactly the same way as a Semaphore. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/45ZKM62GS5EINE75KNOLFTJ3AHOYVHRZ/ Code of Conduct: http://python.org/psf/codeofconduct/