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

Allow closing the connection/session #278

Open
FRosner opened this issue Feb 19, 2024 · 2 comments
Open

Allow closing the connection/session #278

FRosner opened this issue Feb 19, 2024 · 2 comments

Comments

@FRosner
Copy link

FRosner commented Feb 19, 2024

Is your feature request related to a problem? Please describe.

We can open a client, but we cannot close the session. We have to work around it providing our own context manager which accesses a private variable in PrometheusConnect:

    def __enter__(self):
        return self._prometheus

    def __exit__(self, exc_type, exc_val, exc_tb):
        if self._prometheus._session:
            self._prometheus._session.close()
        return False

Describe the solution you'd like

Would be nice to have a close method, or even also implement context manager.

Describe alternatives you've considered

Not sure if there are any. We need to be able to not leak connections.

@4n4nd
Copy link
Owner

4n4nd commented Feb 21, 2024

@FRosner with the latest release, you can pass a custom session to PrometheusConnect. Does that work for your usecase?

@FRosner
Copy link
Author

FRosner commented Feb 26, 2024

@4n4nd thanks! I guess it still leaves it to us to close the session, but it's for sure better than accessing the private variable. Do you think there's value in providing a close method that closes the session (may it be provided or not), and maybe even the context manager methods?

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