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

fix: add method to close httplib2 connections #1038

Merged
merged 3 commits into from
Sep 23, 2020

Conversation

busunkim96
Copy link
Contributor

Fixes #618 🦕

httplib2 leaves sockets open by default. This can lead to situations where programs run out of available sockets. httplib2 added a method last year to clean up connections. https://github.com/httplib2/httplib2/blob/9bf300cdc372938f4237150d5b9b615879eb51a1/python3/httplib2/__init__.py#L1498-L1506

This PR adds two ways to close http connections. The interface is intentionally similar to the proposed design for GAPIC clients. googleapis/gapic-generator-python#575

explicitly call close:

from googleapiclient import discovery

service = discovery.build("drive", "v3")
service.drives().list()
service.close()

context manager:

from googleapiclient import discovery

with discovery.build("drive", "v3") as service:
    service.drives().list()

# service.__exit__() is called which calls service.close()

@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Sep 22, 2020
@busunkim96 busunkim96 added the automerge Merge the pull request once unit tests and other checks pass. label Sep 22, 2020
@gcf-merge-on-green
Copy link

Your PR has attempted to merge for 3 hours. Please check that all required checks have passed, you have an automerge label, and that all your reviewers have approved the PR

@gcf-merge-on-green
Copy link

Merge-on-green attempted to merge your PR for 6 hours, but it was not mergeable because either one of your required status checks failed, or one of your required reviews was not approved. Learn more about your required status checks here: https://help.github.com/en/github/administering-a-repository/enabling-required-status-checks. You can remove and reapply the label to re-run the bot.

@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Sep 23, 2020
@tswast tswast requested a review from a team as a code owner September 23, 2020 14:51
@busunkim96 busunkim96 merged commit 98888da into googleapis:master Sep 23, 2020
@busunkim96 busunkim96 deleted the context-manager-for-httplib2 branch September 23, 2020 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

discovery.build( ) raises ResourceWarning: unclosed <ssl.SSLSocket fd=13,
2 participants