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

ConnectionPool has no close #229

Open
kimharo opened this issue Nov 7, 2019 · 1 comment
Open

ConnectionPool has no close #229

kimharo opened this issue Nov 7, 2019 · 1 comment

Comments

@kimharo
Copy link

kimharo commented Nov 7, 2019

with happybase.ConnectionPool(10) as pool: <- need this or close() function
  with pool.connection() as conn:
     xxxxxx

there is no remove resource in ConnectionPool. so i close connection manually.

        try:
            while True:
                conn = pool._queue.get(True, 0)
                conn.close()
        except Exception as e:
            pass
@ljluestc
Copy link

This can help simplify your code:

with happybase.ConnectionPool(10) as pool:
    with pool.connection() as conn:
        # Your code here

# At this point, all connections in the pool will be closed and removed

By using the with statement, the connections will be automatically closed when they go out of scope, and the pool.clear() method will ensure that any remaining connections are closed and removed when you exit the context.

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

No branches or pull requests

2 participants