Uncoupled the api_client instance from the RequestSync object

This commit is contained in:
Rudi Grinberg 2012-10-23 17:00:22 -04:00
parent 9169893e4d
commit f718070d3c

View file

@ -18,10 +18,18 @@ class RequestSync(threading.Thread,Loggable):
to airtime. In the process it packs the requests and retries for to airtime. In the process it packs the requests and retries for
some number of times some number of times
""" """
def __init__(self, watcher, requests):
@classmethod
def create_with_api_client(cls, watcher, requests):
apiclient = ac.AirtimeApiClient.create_right_config()
self = cls(watcher, requests, apiclient)
return self
def __init__(self, watcher, requests, apiclient):
threading.Thread.__init__(self) threading.Thread.__init__(self)
self.watcher = watcher self.watcher = watcher
self.requests = requests self.requests = requests
self.apiclient = apiclient
self.retries = 1 self.retries = 1
self.request_wait = 0.3 self.request_wait = 0.3
@ -209,7 +217,8 @@ class WatchSyncer(ReportHandler,Loggable):
requests = copy.copy(self.__queue) requests = copy.copy(self.__queue)
def launch_request(): def launch_request():
# Need shallow copy here # Need shallow copy here
t = RequestSync(watcher=self, requests=requests) t = RequestSync.create_with_api_client(watcher=self,
requests=requests)
t.start() t.start()
self.__current_thread = t self.__current_thread = t
self.__requests.append(launch_request) self.__requests.append(launch_request)