def _read_stdin(self): while True: yield select.select([sys.stdin], [], []) line = sys.stdin.readline() if not line: break if not line.strip(): continue in_dict = json.loads(line) yield idiokit.send(events.Event(in_dict))
def _read_stdin(self): loads = json.JSONDecoder(parse_float=unicode, parse_int=unicode).decode while True: yield select.select([sys.stdin], [], []) line = sys.stdin.readline() if not line: break if not line.strip(): continue in_dict = loads(line) yield idiokit.send(events.Event(in_dict))
def collect_decode(socks): readable = [] while True: while not readable: readable, _, _ = yield select.select(socks, (), ()) readable = list(readable) sock = readable.pop() length_bytes = yield _recvall_stream(sock, 4) length, = struct.unpack("!I", length_bytes) msg_bytes = yield _recvall_stream(sock, length) yield idiokit.send(cPickle.loads(msg_bytes))
def distribute_encode(socks): writable = [] while True: to_all, msg = yield idiokit.next() msg_bytes = cPickle.dumps(msg, cPickle.HIGHEST_PROTOCOL) data = struct.pack("!I", len(msg_bytes)) + msg_bytes if to_all: for sock in socks: yield sock.sendall(data) writable = [] else: while not writable: _, writable, _ = yield select.select((), socks, ()) writable = list(writable) yield writable.pop().sendall(data)