Thread safe client lib on app engine (python)

16 views
Skip to first unread message

Zoltan Molnar via StackOverflow

unread,
May 17, 2017, 4:13:09 AM5/17/17
to google-appengin...@googlegroups.com

I found a little sample code about bigquery insert in one of Google's git repositories.

https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/appengine/standard/bigquery/main.py

If you see the app.yaml it says this code should be thread safe, but if I'm lokking at the client lib's documentation (https://developers.google.com/api-client-library/python/guide/thread_safety) it should not be thread safe. I'm a little bit confused now, that my following code is thread safe or not? It's running on app engine standard env.

import pprint

from googleapiclient.discovery import build
from oauth2client.client import GoogleCredentials


credentials = GoogleCredentials.get_application_default()

# Create the bigquery api client
service = build('bigquery', 'v2', credentials=credentials)

response = service.datasets().list(projectId='PROJECTID').execute()

pprint.pprint(response)

---- UPDATE ---- After Tim's answer I changed my code to the following. This should be good now:

import pprint

from googleapiclient.discovery import build
from oauth2client.contrib.appengine import AppAssertionCredentials
import httplib2


credentials = AppAssertionCredentials(scope='https://www.googleapis.com/auth/bigquery')


# Create the bigquery api client
service = build('bigquery', 'v2')


def get():
    # authorize http object with client credentials
    http = credentials.authorize(httplib2.Http())
    response = service.datasets().list(projectId='PROJECTID').execute(http=http)

    pprint.pprint(response)


Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/37806753/thread-safe-client-lib-on-app-engine-python
Reply all
Reply to author
Forward
0 new messages