Async concurrency and queue limiter with server-style backlog control.
Project description
Async Backlog Limiter
A lightweight, zero-dependency Python library to limit concurrent execution and queue size of asynchronous tasks — simulating a TCP-style backlog for async servers, job runners, or microservices to ensure overload protection.
📦 Installation
pip install async-backlog-limiter
🛠️ Usage
- If more than
capacityconcurrent requests are running, additional ones will wait. - If the
total number of active + waitingrequests exceedsqueue_limit, new ones are immediately rejected with aRateLimitExceededexception.
import asyncio
from async_backlog_limiter import AsyncBacklogLimiter, RateLimitExceeded
limiter = AsyncBacklogLimiter(capacity=5, queue_limit=10)
async def handle_request():
try:
async with limiter():
# Your async work here
await asyncio.sleep(1)
except RateLimitExceeded:
print("Request rejected due to overload.")
# Run many tasks
await asyncio.gather(*[handle_request() for _ in range(20)])
# Get current statistics about the limiter's state
limiter.stats()
🧪 Tests
This project includes a comprehensive test suite using unittest.
To run tests:
python -m unittest discover -s tests
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file async_backlog_limiter-0.1.3.tar.gz.
File metadata
- Download URL: async_backlog_limiter-0.1.3.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.12.10 Linux/6.11.0-1014-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90b9840bc33265ddf052c6aa207f9263126a68045f6312e3191636609b8cc870
|
|
| MD5 |
047ed2a8388819ab1f0c371eeeccceb6
|
|
| BLAKE2b-256 |
09ff26ffdd1d7acdb9bdda3818d40eae57112d8f7131a3b3503519c3ae4a391b
|
File details
Details for the file async_backlog_limiter-0.1.3-py3-none-any.whl.
File metadata
- Download URL: async_backlog_limiter-0.1.3-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.12.10 Linux/6.11.0-1014-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89b1de40288a2ebe1debfb82a7ce3b8e238ea07b5f7bfa64bdd6315002215668
|
|
| MD5 |
d322cfb5edc94f9b3633b21f39285828
|
|
| BLAKE2b-256 |
94f4c329571709f8f73d329a26eaca6f1ca23b0320580a11df5c73eb52cf9806
|