or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/asyncstdlib@3.13.x
tile.json

tessl/pypi-asyncstdlib

tessl install tessl/pypi-asyncstdlib@3.13.0

The 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%

task.mdevals/scenario-1/

Resource Pool Manager

Build a dynamic resource pool manager that handles multiple asynchronous resources with proper cleanup guarantees.

Overview

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.

Requirements

Implement a ResourcePoolManager class that manages multiple async resources with the following capabilities:

Dynamic Resource Registration

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.

Cleanup Callback Registration

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.

Manual Resource Cleanup

The manager must provide a method to immediately clean up all resources in reverse order (LIFO - Last In First Out).

Context Manager Protocol

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.

Test Cases

  • An empty resource pool completes successfully when used as a context manager @test
  • When three async context managers are added to a pool, all three are entered and their results are returned @test
  • When cleanup callbacks are registered, they execute in reverse order (LIFO) during teardown @test
  • When the second resource fails during entry, the first resource is properly cleaned up before propagating the exception @test

Implementation

@generates

API

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)
        """
        pass

Dependencies { .dependencies }

asyncstdlib { .dependency }

Provides async-compatible utilities for context management and resource handling.