prometheus-api-client-python
prometheus-api-client-python copied to clipboard
Allow closing the connection/session
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.
@FRosner with the latest release, you can pass a custom session to PrometheusConnect. Does that work for your usecase?
@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?