Пример #1
0
def process(rnd, requests):
    requester = Requester()
    with requester.requests():
        # Process all requests.
        for req in requests:
            req = Bunch(req)
            if 'flags' not in req:
                req.flags = 0
            if 'content' in req:
                req.content = Bunch(req.content)
            ROUTER[req.action, req.type](requester, req)
    requester.submit(rnd)
Пример #2
0
def process(requests):
    requester = Requester()
    with requester.requests():
        # Process all requests.
        for req in requests:
            req = Bunch(req)
            if 'flags' not in req:
                req.flags = 0
            if 'content' in req:
                req.content = Bunch(req.content)
            print(req, file=sys.stderr)
            ROUTER[req.action, req.type](requester, req)
    requester.submit(RENDERER)
Пример #3
0
def render(rnd, board_id=1):
    # Trigger a redraw.
    requester = Requester()
    with requester.requests():
        requester.update_board(board_id)
    requester.submit(rnd)

    # Get the image.
    img = rnd.get_png(board_id)

    # Return as PNG
    output = io.BytesIO(img)
    return output
Пример #4
0
def render():
    # TODO: find board id?
    board_id = 1

    # Trigger a redraw.
    requester = Requester()
    with requester.requests():
        requester.update_board(board_id)
    requester.submit(RENDERER)

    # Get the image.
    img = RENDERER.get_png(1)

    # Return as PNG
    output = io.BytesIO(img)
    return send_file(output, mimetype='image/png', as_attachment=False)
Пример #5
0
async def process_requests(websocket):
    rqr = Requester()
    rnd = Renderer()
    created = False

    while True:
        try:
            msg = await websocket.recv()
            logger.debug("new message")
            msg = json.loads(msg)
            if 'set_session' in msg:
                uri = msg['set_session']['uri']
                st_name = msg['set_session']['spike_times']
                sd_name = msg['set_session']['spike_depths']
                t0 = msg['set_session'].get('start_time', 0)
                t1 = msg['set_session'].get('stop_time', 1)

                create(rqr, rnd, uri, st_name, sd_name, t0=t0, t1=t1)

            elif 'update_time' in msg:
                t0 = msg['update_time'].get('start_time', 0)
                t1 = msg['update_time'].get('stop_time', 1)

                update(rqr, rnd, uri, st_name, sd_name, t0=t0, t1=t1)

            img = render(rqr, rnd, 1)
            logger.debug(
                f"sending back the image with {img.getbuffer().nbytes} bytes..."
            )
            img.seek(0)
            await websocket.send(img)
        except (websockets.ConnectionClosedOK,
                websockets.ConnectionClosedError):
            logger.debug("server connection closed")
            break
        except Exception as e:
            logger.error(traceback.format_exc())
            break
    logger.debug("server stopped")