7 class ThreadSafeApiCache(object):
8 """Threadsafe wrapper for API objects.
10 This stores and returns a different api object per thread, because httplib2
11 which underlies apiclient is not threadsafe.
15 def __init__(self, apiconfig=None, keep_params={}):
17 apiconfig = config.settings()
18 self.apiconfig = copy.copy(apiconfig)
19 self.local = threading.local()
20 self.keep = keep.KeepClient(api_client=self, **keep_params)
23 if 'api' not in self.local.__dict__:
24 self.local.api = api.api_from_config('v1', apiconfig=self.apiconfig)
27 def __getattr__(self, name):
28 # Proxy nonexistent attributes to the thread-local API client.
29 if name == "api_token":
30 return self.apiconfig['ARVADOS_API_TOKEN']
31 return getattr(self.localapi(), name)