GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: add method to close httplib2 connections by busunkim96 · Pull Request #1038 · googleapis/google-api-python-client

Conversation

@busunkim96

@busunkim96 busunkim96 commented Sep 22, 2020

Copy link
Copy Markdown
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()

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
busunkim96 added 2 commits September 21, 2020 23:59
@busunkim96
fix: add method to close httplib2 connections
8d16405
@busunkim96
chore: remove extra files
0f6e533
@busunkim96
busunkim96 requested review from crwilcox, software-dov and tswast September 22, 2020 00:16
@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

gcf-merge-on-green Bot commented Sep 23, 2020

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gcf-merge-on-green

gcf-merge-on-green Bot commented Sep 23, 2020

Copy link
Copy Markdown

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@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
Merge branch 'master' into context-manager-for-httplib2
3547110
@tswast
tswast requested a review from a team September 23, 2020 14:51
tswast
tswast approved these changes Sep 23, 2020
View reviewed changes
@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
gcf-merge-on-green Bot pushed a commit that referenced this pull request Sep 23, 2020
@release-please
chore: release 1.12.2 (#1044)
2d076b8
🤖 I have created a release \*beep\* \*boop\* 
---
### [1.12.2](https://www.github.com/googleapis/google-api-python-client/compare/v1.12.1...v1.12.2) (2020-09-23)


### Bug Fixes

* add method to close httplib2 connections ([#1038](https://www.github.com/googleapis/google-api-python-client/issues/1038)) ([98888da](https://www.github.com/googleapis/google-api-python-client/commit/98888dadf04e7e00524b6de273d28d02d7abc2c0)), closes [#618](https://www.github.com/googleapis/google-api-python-client/issues/618) [/github.com/httplib2/httplib2/blob/9bf300cdc372938f4237150d5b9b615879eb51a1/python3/httplib2/__init__.py#L1498-L1506](https://www.github.com/googleapis//github.com/httplib2/httplib2/blob/9bf300cdc372938f4237150d5b9b615879eb51a1/python3/httplib2/__init__.py/issues/L1498-L1506) [googleapis/gapic-generator-python#575](https://www.github.com/googleapis/gapic-generator-python/issues/575)
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please).
@yohplala yohplala mentioned this pull request Sep 24, 2020
When using http.close()? httplib2/httplib2#178
Closed
@davidbeers davidbeers mentioned this pull request Nov 13, 2020
Client: client does not close SSL socket after request completes googlemaps/google-maps-services-python#386
Open
This was referenced May 31, 2026
test: connection leak test test_discovery_http_is_closed is shadowed and syntactically invalid #2757
Open
test: restore and fix shadowed test_discovery_http_is_closed #2758
Open
@skippdot skippdot mentioned this pull request Sep 1, 2026
fix: restore shadowed test_discovery_http_is_closed test #2801
Open
@cristianchiriac cristianchiriac mentioned this pull request Sep 17, 2026
test: remove duplicate Discovery class that shadowed test_discovery_http_is_closed #2819
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@tswast tswast tswast approved these changes
@crwilcox crwilcox Awaiting requested review from crwilcox
@software-dov software-dov Awaiting requested review from software-dov

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

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

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@busunkim96 @tswast
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.