1 from __future__ import absolute_import
3 from builtins import object
8 import arvados.keep as keep
9 import arvados.config as config
11 class ThreadSafeApiCache(object):
12 """Threadsafe wrapper for API objects.
14 This stores and returns a different api object per thread, because httplib2
15 which underlies apiclient is not threadsafe.
19 def __init__(self, apiconfig=None, keep_params={}):
21 apiconfig = config.settings()
22 self.apiconfig = copy.copy(apiconfig)
23 self.local = threading.local()
24 self.keep = keep.KeepClient(api_client=self, **keep_params)
27 if 'api' not in self.local.__dict__:
28 self.local.api = arvados.api_from_config('v1', apiconfig=self.apiconfig)
31 def __getattr__(self, name):
32 # Proxy nonexistent attributes to the thread-local API client.
33 if name == "api_token":
34 return self.apiconfig['ARVADOS_API_TOKEN']
35 return getattr(self.localapi(), name)