def do_GET(environ, start_response) -> None:
    global pr

    if environ.get('PATH_INFO', '') == "/start_profile":
        pr.enable()
        start_response('200 OK', [])
        return b'profiling enabled',

    if environ.get('PATH_INFO', '') == "/stop_profile":
        pr.disable()
        start_response('200 OK', [])
        return b'profiling disabled',

    if environ.get('PATH_INFO', '') == "/get_profile":
        s = io.StringIO()
        ps = pstats.Stats(pr, stream=s).sort_stats('tottime')
        ps.print_stats()
        start_response('200 OK', [])
        return s.getvalue().encode("utf-8"),

    server_clock = server.calculate_server_clock()

    start_response(
        '200 OK',
        [("Access-Control-Allow-Origin", "*"),
         ("Access-Control-Allow-Headers", "Content-Type, X-Event-Data"),
         ("Access-Control-Expose-Headers", "X-Audio-Metadata"),
         ("X-Audio-Metadata",
          json.dumps({
              "server_clock": server_clock,
              "server_sample_rate": server.SAMPLE_RATE,
          })), ("Content-Type", "application/octet-stream")])
    # If we give a 0-byte response, Chrome Dev Tools gives a misleading error (see https://stackoverflow.com/questions/57477805/why-do-i-get-fetch-failed-loading-when-it-actually-worked)
    return b'ok',
Пример #2
0
def query_string():
  return "read_clock=%s&userid=%s&username=%s" % (
    (server.calculate_server_clock(),
     userid,
     username))