Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the Pool's available_connections property #122

Conversation

stankudrow
Copy link
Contributor

The pool.available_connections property shows the number of connections one can request from the pool.

If a pool object is requested to give out a connection when the number of acquired connections is equal to the pool.maxsize property, the AsynchPoolError is raised because the pool cannot give birth to a connection when its capacities are exceeded.

A possible use case:

async with pool:
    # some code
    if pool.availlable_connections:
        conn_ctx_manager = pool.connection()
       # one can safely request a connection from the pool
    else:
        # requesting a connection from the pool will lead to the AsynchPoolError

The source of inspiration: the issue #121 by @itssimon .

@stankudrow
Copy link
Contributor Author

I think these Pool properties are error-prone and are better to be replaced with async methods, e.g., get_free_connections() with async with self._lock context.

Perhaps this PR should be closed and in favour of the PR with properties replaced with corresponding coro methods for ensuring the coroutine-safety.

@stankudrow stankudrow marked this pull request as draft October 20, 2024 18:11
@stankudrow stankudrow marked this pull request as ready for review October 20, 2024 20:48
@stankudrow stankudrow marked this pull request as draft October 20, 2024 21:03
@stankudrow stankudrow closed this Oct 21, 2024
@stankudrow stankudrow deleted the introduce-pool-available-connectios-property branch October 21, 2024 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant