tessl install tessl/pypi-asyncstdlib@3.13.0The missing async toolbox - re-implements functions and classes of the Python standard library to make them compatible with async callables, iterables and context managers
Agent Success
Agent success rate when using this tile
84%
Improvement
Agent success rate improvement when using this tile compared to baseline
3.36x
Baseline
Agent success rate without this tile
25%
Build a dynamic resource pool manager that handles multiple asynchronous resources with proper cleanup guarantees.
Create a resource pool manager that can dynamically acquire multiple async resources (like database connections, file handles, or network connections) and ensure all resources are properly cleaned up even if errors occur during acquisition or usage.
Implement a ResourcePoolManager class that manages multiple async resources with the following capabilities:
The manager must allow adding async context managers dynamically after creation. Each added context manager should be entered immediately and its result returned to the caller.
The manager must support registering cleanup callbacks that execute during teardown. Callbacks can be either synchronous or asynchronous functions and should receive any provided arguments.
The manager must provide a method to immediately clean up all resources in reverse order (LIFO - Last In First Out).
The manager must implement the async context manager protocol (async with statement support) and properly clean up all resources when exiting the context, even if exceptions occur.
@generates
class ResourcePoolManager:
"""
Manages multiple async context managers with dynamic registration and proper cleanup.
"""
async def add_resource(self, context_manager):
"""
Add an async context manager to the pool.
Args:
context_manager: An async context manager instance
Returns:
The result of entering the context manager
"""
pass
def add_cleanup(self, callback, *args, **kwargs):
"""
Register a cleanup callback to be executed during teardown.
Args:
callback: A callable (can be sync or async) to execute during cleanup
*args: Positional arguments to pass to the callback
**kwargs: Keyword arguments to pass to the callback
"""
pass
async def close(self):
"""
Immediately close all resources in LIFO order.
"""
pass
async def __aenter__(self):
"""
Enter the resource pool context.
Returns:
self
"""
pass
async def __aexit__(self, exc_type, exc_val, exc_tb):
"""
Exit the resource pool context, cleaning up all resources in LIFO order.
Args:
exc_type: Exception type if an exception occurred
exc_val: Exception value if an exception occurred
exc_tb: Exception traceback if an exception occurred
Returns:
None (do not suppress exceptions)
"""
passProvides async-compatible utilities for context management and resource handling.