while not self.die:
apimethod = getattr(self.twitter.api, self.method)
statuses = self.twitter.api_wrapper(apimethod, *self.args, **self.kwargs)
-
# If Timeline update
if statuses:
# Add statuses to timeline
# update lastid
self.lastid = statuses[-1].id
self.kwargs["since_id"] = self.lastid
-
# Reload lock
self.lock.clear()
if self.interval != -1:
self.me = None
self.my_name = screen_name
#self.threads = list()
+ self.apilock = threading.Lock()
# User, Status Buffer
self.users = dict()
def api_wrapper(self, method, *args, **kwargs):
for i in range(3):
try:
+ self.apilock.acquire()
response = None
response = method(*args, **kwargs)
break
break
if i >= 3:
- self.on_twitterapi_error(self, e)
+ self.on_twitterapi_error(method, e)
+
print >>sys.stderr, "[Error] %d: TwitterAPI %s (%s)" % (i, e, method.func_name)
- time.sleep(5)
except socket.timeout:
print >>sys.stderr, "[Error] %d: TwitterAPI timeout (%s)" % (i, method.func_name)
except Exception, e:
print >>sys.stderr, "[Error] %d: TwitterAPI %s (%s)" % (i, e, method.func_name)
+ finally:
+ self.apilock.release()
+
+ time.sleep(5)
return response