1
2
3
4
5 from __future__ import absolute_import
6
7 from builtins import object
8 import copy
9 import threading
10
11 import arvados
12 import arvados.keep as keep
13 import arvados.config as config
14
16 """Threadsafe wrapper for API objects.
17
18 This stores and returns a different api object per thread, because httplib2
19 which underlies apiclient is not threadsafe.
20
21 """
22
23 - def __init__(self, apiconfig=None, keep_params={}, api_params={}):
24 if apiconfig is None:
25 apiconfig = config.settings()
26 self.apiconfig = copy.copy(apiconfig)
27 self.api_params = api_params
28 self.local = threading.local()
29
30
31
32
33 self.localapi()
34
35 self.keep = keep.KeepClient(api_client=self, **keep_params)
36
38 if 'api' not in self.local.__dict__:
39 self.local.api = arvados.api_from_config('v1', apiconfig=self.apiconfig,
40 **self.api_params)
41 return self.local.api
42
44
45 if name == "api_token":
46 return self.apiconfig['ARVADOS_API_TOKEN']
47 return getattr(self.localapi(), name)
48