本文整理汇总了Python中tornado.options.options.url方法的典型用法代码示例。如果您正苦于以下问题:Python options.url方法的具体用法?Python options.url怎么用?Python options.url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.options.options
的用法示例。
在下文中一共展示了options.url方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_tests
# 需要导入模块: from tornado.options import options [as 别名]
# 或者: from tornado.options.options import url [as 别名]
def run_tests():
url = options.url + '/getCaseCount'
control_ws = yield websocket_connect(url, None)
num_tests = int((yield control_ws.read_message()))
logging.info('running %d cases', num_tests)
msg = yield control_ws.read_message()
assert msg is None
for i in range(1, num_tests + 1):
logging.info('running test case %d', i)
url = options.url + '/runCase?case=%d&agent=%s' % (i, options.name)
test_ws = yield websocket_connect(url, None, compression_options={})
while True:
message = yield test_ws.read_message()
if message is None:
break
test_ws.write_message(message, binary=isinstance(message, bytes))
url = options.url + '/updateReports?agent=%s' % options.name
update_ws = yield websocket_connect(url, None)
msg = yield update_ws.read_message()
assert msg is None
IOLoop.instance().stop()
示例2: cull_idle
# 需要导入模块: from tornado.options import options [as 别名]
# 或者: from tornado.options.options import url [as 别名]
def cull_idle(url, api_token, timeout):
"""cull idle single-user servers"""
auth_header = {
'Authorization': 'token %s' % api_token
}
req = HTTPRequest(url=url + '/users',
headers=auth_header,
)
now = datetime.datetime.utcnow()
cull_limit = now - datetime.timedelta(seconds=timeout)
client = AsyncHTTPClient()
resp = yield client.fetch(req)
users = json.loads(resp.body.decode('utf8', 'replace'))
futures = []
for user in users:
last_activity = parse_date(user['last_activity'])
if user['server'] and last_activity < cull_limit:
app_log.info("Culling %s (inactive since %s)", user['name'], last_activity)
req = HTTPRequest(url=url + '/users/%s/server' % user['name'],
method='DELETE',
headers=auth_header,
)
futures.append((user['name'], client.fetch(req)))
elif user['server'] and last_activity > cull_limit:
app_log.debug("Not culling %s (active since %s)", user['name'], last_activity)
for (name, f) in futures:
yield f
app_log.debug("Finished culling %s", name)
示例3: cull_idle
# 需要导入模块: from tornado.options import options [as 别名]
# 或者: from tornado.options.options import url [as 别名]
def cull_idle(url, api_token, timeout):
#last valid activity timestame
cull_limit = datetime.datetime.utcnow() - datetime.timedelta(seconds=timeout)
#get user list
hub_api_authorization_header = { 'Authorization': 'token %s' % api_token}
users_request = HTTPRequest(url=url + '/users', headers=hub_api_authorization_header )
#run request tornado-asynchronously, extract user list (contains more information)
resp = yield AsyncHTTPClient().fetch(users_request)
all_users = json.loads(resp.body.decode('utf8', 'replace'))
#build a bunch of (asynchronous) HTTP request futures...
stop_notebook_futures = []
servers_to_check = []
dont_cull_these = set()
for user in all_users:
#extract last activity time, determine cullability of the server.
last_activity = parse_date(user['last_activity'])
should_cull = last_activity.replace(tzinfo=None) < cull_limit.replace(tzinfo=None)
user_name = user['name']
app_log.debug("checking %s, last activity: %s, server: %s" % (user_name, last_activity, user['server']) )
if not should_cull:
dont_cull_these.add(user_name)
#server should be culled:
if user['server'] and should_cull:
app_log.info("Culling %s (inactive since %s)", user_name, last_activity)
stop_user_request = HTTPRequest(url=url + '/users/%s/server' % user_name,
method='DELETE',
headers=hub_api_authorization_header )
stop_notebook_futures.append( (user_name, AsyncHTTPClient().fetch(stop_user_request)) )
#Server status is None, which means actual status needs to be checked.
if not user['server'] and should_cull:
servers_to_check.append(user_name)
#server should not be culled, just a log statement
if user['server'] and not should_cull:
app_log.info("Not culling %s (active since %s)", user['name'], last_activity)
# Cull notebooks using normal API.
for (user_name, cull_request) in stop_notebook_futures:
try:
yield cull_request #this line actually runs the api call to kill a server
except HTTPError:
#Due to a bug in Jupyterhub
app_log.error("Something went wrong culling %s, will be manually killing it.", user_name)
servers_to_check.append( user_name )
continue
app_log.info("Finished culling %s", user_name)
for user_name in servers_to_check:
if user_name not in dont_cull_these:
yield manually_kill_server(user_name)