-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Based on the docs here, a Google API service should not be shared across threads because of lack of thread safety in httplib2
.
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.
Problematic code
In api.py
, a ProcurementApi is created at the module level.
doit-easily-marketplace/api/api.py
Line 21 in 7b0eb8b
procurement_api = ProcurementApi(settings.MARKETPLACE_PROJECT) |
I believe this creates a single instance of the service, which would be shared across threads.
doit-easily-marketplace/api/procurement_api.py
Lines 20 to 24 in 7b0eb8b
class ProcurementApi(object): | |
"""Utilities for interacting with the Procurement API.""" | |
def __init__(self, project_id): | |
self.service = build(PROCUREMENT_API, "v1", cache_discovery=False) |
For us, this has resulted in some head-scratching HTTP and SSL errors, of which I'm fairly certain this is the cause.