Async Batch Engine
An asynchronous batch processing engine for Python.
Installation
pip install abatchtaskpool
Usage
from typing import Any, List
import asyncio
from abatchtaskpool.async_batch_engine import AsyncBatchEngine
async def example_processing_function(inputs: List[Any]) -> List[Any]:
"""示例批处理函数"""
await asyncio.sleep(1) # 模拟处理耗时
return [f"Processed_{item}" for item in inputs]
async def main():
# 创建引擎实例
engine = AsyncBatchEngine(
processing_function=example_processing_function,
batch_size=5,
wait_timeout=0.5,
num_workers=2
)
# 提交任务并获取结果
tasks = [
engine.add_request(f"task_{i}", f"req_{i}")
for i in range(10)
]
results = await asyncio.gather(*tasks)
# 输出结果
for result in results:
print(f"Result: {result}")
# 停止引擎
await engine.stop()
if __name__ == "__main__":
asyncio.run(main())
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
abatchtaskpool-0.1.0.tar.gz
(3.8 kB
view details)
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 abatchtaskpool-0.1.0.tar.gz.
File metadata
- Download URL: abatchtaskpool-0.1.0.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/4.0.2 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
419e60db4436fdbaa3831e7b792f779be557b66adc854a95eea9e03a5eacec06
|
|
| MD5 |
b18a3c4d61346bc78226236324c3817b
|
|
| BLAKE2b-256 |
1ddb95def550b684c445df5c890c21d1aecb852b9edfe1d6a68ba9198180c2d4
|
File details
Details for the file abatchtaskpool-0.1.0-py3-none-any.whl.
File metadata
- Download URL: abatchtaskpool-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/4.0.2 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
705d563fc9f526d77bb5b19bc7da668a21cda9c41eb1273a36885586dbdefa4a
|
|
| MD5 |
415e952a57f2485a392bd5ca9255d8ab
|
|
| BLAKE2b-256 |
ef888e84d254cdc88ba0ed7cc0282604b5e2c5ec8153f45e514bc13ea18bfdbc
|