Example #1
0
def listen_and_reply(sock, compute_func):
    while True:
        req = protocol.from_encoded_message(sock.recv())
        start = monotonic()
        # TODO: try/catch
        ret = compute_func(req)
        end = monotonic()
        t = end - start
        diff = []
        diff.append(math.floor(t))
        diff.append((t - diff[0]) * math.pow(10, 9))
        sock.send(protocol.to_encoded_message(ret, diff))
Example #2
0
def test_encode():
    d = dict(value='abc')
    assert p.to_encoded_message(d, [0,0]) == '{"stats": {"result": [0, 0]}, "out": [{"value": "YWJj"}]}'