def write(stream, msg): """write data to a stream""" msg = dumps(msg) yield stream.write(msg + sentinel)