本文整理汇总了Python中neubot.log.LOG.start_streaming方法的典型用法代码示例。如果您正苦于以下问题:Python LOG.start_streaming方法的具体用法?Python LOG.start_streaming怎么用?Python LOG.start_streaming使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neubot.log.LOG
的用法示例。
在下文中一共展示了LOG.start_streaming方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runner_api
# 需要导入模块: from neubot.log import LOG [as 别名]
# 或者: from neubot.log.LOG import start_streaming [as 别名]
def runner_api(stream, request, query):
''' Implements /api/runner '''
response = Message()
#
# DO NOT allow to start a test when another test is in
# progress because I have noticed that is confusing both
# from
# command line and WUI.
#
if RUNNER_CORE.test_is_running():
raise ConfigError('A test is already in progress, try again later')
#
# If there is not a query string this API is just
# a no-operation and returns an empty JSON body to
# keep happy the AJAX code.
#
if not query:
response.compose(code='200', reason='Ok', body='{}',
mimetype='application/json')
stream.send_response(request, response)
return
options = cgi.parse_qs(query)
#
# If the query does not contain the name of the
# test, this is an error and we must notify that
# to the caller. Raise ConfigError, which will
# be automatically transformed into a 500 message
# with the proper body and reason.
#
if not 'test' in options:
raise ConfigError('Missing "test" option in query string')
test = options['test'][0]
#
# Simple case: the caller does not want to follow the
# test via log streaming. We can immediately start
# the test using the runner and, if everything is OK,
# we can send a succesful response, with an empty JSON
# body to keep happy the AJAX code.
#
if not 'streaming' in options or not utils.intify(options['streaming'][0]):
RUNNER_CORE.run(test, runner_api_done)
response.compose(code='200', reason='Ok', body='{}',
mimetype='application/json')
stream.send_response(request, response)
return
#
# More interesting case: the caller wants to see the log
# messages during the test via the log streaming API.
# We prepare a succesful response terminated by EOF and
# then arrange things so that every new log message will
# be copied to the HTTP response.
# Then we kick off the runner, and note that we do that
# AFTER we setup the response for eventual runner errors
# to be copied to the HTTP response.
# The runner core will automatically close all attached
# streams at the end of the test.
#
response.compose(code='200', reason='Ok',
up_to_eof=True, mimetype='text/plain')
stream.send_response(request, response)
LOG.start_streaming(stream)
RUNNER_CORE.run(test, runner_api_done)