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

DevSite Import: Thread Safety #687

Closed
grant opened this issue Jun 6, 2019 · 1 comment
Closed

DevSite Import: Thread Safety #687

grant opened this issue Jun 6, 2019 · 1 comment
Assignees
Labels
type: docs Improvement to the documentation for an API.

Comments

@grant
Copy link
Contributor

grant commented Jun 6, 2019

Notice: This DevSite page will soon be deleted per b/133171590. Please add this sample to GitHub if it is relevant still:

https://developers.google.com/api-client-library/python/guide/thread_safety


Thread Safety

This page contains important information about the thread safety of this library.

The httplib2.Http() objects are not thread-safe

The google-api-python-client library is built on top of the httplib2 library, which is not thread-safe. Therefore, if you are running as a multi-threaded application, each thread that you are making requests from must have its own instance of httplib2.Http().

The easiest way to provide threads with their own httplib2.Http() instances is to either override the construction of it within the service object or to pass an instance via the http argument to method calls.

# Create a new Http() object for every request
  def build_request(http, *args, **kwargs):
    new_http = httplib2.Http()
    return googleapiclient.http.HttpRequest(new_http, *args, **kwargs)
  service = build('api_name', 'api_version', requestBuilder=build_request)

  # Pass in a new Http() manually for every request
  service = build('api_name', 'api_version')
  http = httplib2.Http()
  service.stamps().list().execute(http=http)

Credential Storage objects are thread-safe

All Storage objects defined in this library are thread-safe, and multiple processes and threads can operate on a single store.

In some cases, this library automatically refreshes expired OAuth 2.0 tokens. When many threads are sharing the same set of credentials, the threads cooperate to minimize the total number of token refresh requests sent to the server.

@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Jun 7, 2019
@busunkim96 busunkim96 added type: docs Improvement to the documentation for an API. and removed triage me I really want to be triaged. labels Jun 10, 2019
@grant
Copy link
Contributor Author

grant commented Jun 26, 2019

The docs are now added to the docs/ folder.
Fixed with #706.

@grant grant closed this as completed Jun 26, 2019
gaijin03 added a commit to SchedMD/slurm-gcp that referenced this issue Mar 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: docs Improvement to the documentation for an API.
Projects
None yet
Development

No branches or pull requests

3 participants