docker-py icon indicating copy to clipboard operation
docker-py copied to clipboard

Add context manager to the client API

Open feliperuhland opened this issue 3 years ago • 1 comments

ApiClient inherence from requests.session that implements __enter__ and __exit__ methods and the issue #2808 asks to add the same behaviour to the DockerClient.

At the same time, issue #2766 reports a file descriptor leak when _get_raw_response_socket is called.

To fix both requests, I added a set to the ApiClient instance to track every socket open by _get_raw_response_socket and close when the close method is called.

I added a test, and documentation now brings the context manager as an example.

Signed-off-by: Felipe Ruhland [email protected]

feliperuhland avatar Apr 12 '21 22:04 feliperuhland

This should also close #2457.

TBBle avatar Apr 26 '21 02:04 TBBle