本文整理汇总了Python中env.Env.get_usage方法的典型用法代码示例。如果您正苦于以下问题:Python Env.get_usage方法的具体用法?Python Env.get_usage怎么用?Python Env.get_usage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类env.Env
的用法示例。
在下文中一共展示了Env.get_usage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Env
# 需要导入模块: from env import Env [as 别名]
# 或者: from env.Env import get_usage [as 别名]
retry -= 1
logging.warning("Retries left: {0}".format(retry))
time.sleep(5) # Sleep 5 seconds before retrying
# Open a MySQL connection
mysql.connect()
# Set up the environment
env = Env(sys.argv)
username = sys.argv[1]
retry = 12
while retry:
try:
usage = env.get_usage(config.usage_interval)
logging.info("Getting /usage for user: {0}".format(username))
print "Getting /usage for user: {0}".format(username)
break
except Exception, err:
logging.exception("Encountered getting /usage for user: {0}. Error message: {1}".format(username, err))
if err[1] == 403:
logging.info("Exceeded DataSift API Rate Limit. Sleeping for 5 minutes before next retry")
time.sleep(300)
else:
logging.info("Unable to get usage from DataSift. Sleeping for 15 seconds before next retry")
time.sleep(15) # Sleep 15 seconds before retrying
retry -= 1
logging.info("Retries left: {0}".format(retry))