How to use the skypy.deref_as_raw_file function in skypy

To help you get started, we’ve selected a few skypy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mrry / ciel / src / python / skypy / example_producer.py View on Github external
def read_result(reader_result):

    with skypy.RequiredRefs(list(reader_result)):
        cooked_result = skypy.deref(reader_result.ret_output)
        with skypy.deref_as_raw_file(reader_result.extra_outputs[0]) as in_file:
            return (cooked_result, in_file.read())
github mrry / ciel / src / python / skypy / stream_consumer.py View on Github external
try_direct = True
    else:
        try_direct = False
    tests_jar = skypy.package_lookup("java_tests")
    refs = skypy.spawn_exec("java", args={"inputs": [], "argv": [str(run_seconds)], "lib": [tests_jar], "class": "tests.JitteryProducer", "stream_output": True, "pipe_output": try_direct}, n_outputs=2)

    got_bytes = 0

    with skypy.deref_as_raw_file(refs[0], may_stream=may_stream, sole_consumer=try_direct, chunk_size=1048576) as file_in:
        while True:
            file_str = file_in.read(1048576)
            if len(file_str) == 0:
                break
            print >>sys.stderr, "Read", len(file_str), "bytes"
            got_bytes += len(file_str)
    with skypy.deref_as_raw_file(refs[1]) as n_bytes:
        byte_count = n_bytes.read()

    return "Producer wrote %s, I got %d starting with %s" % (byte_count, got_bytes, file_str[:20])
github mrry / ciel / src / python / skypy / pipe_streamer.py View on Github external
def stream_consumer(chunk_size, in_ref, may_stream, use_direct_pipes, must_block):

    bytes_read = 0
    next_threshold = chunk_size
    
    events = []
    events.append(("STARTED", datetime.now()))

    with skypy.deref_as_raw_file(in_ref, may_stream=may_stream, sole_consumer=use_direct_pipes, chunk_size=chunk_size, must_block=must_block) as in_file:

        events.append(("START_READ", datetime.now()))
    
        while True:
            str = in_file.read(4096)
            bytes_read += len(str)
            if len(str) == 0:
                break
            if bytes_read >= next_threshold:
                next_threshold += chunk_size
                events.append(("READ_CHUNK", datetime.now()))
        
    events.append(("FINISHED", datetime.now()))
    
    with skypy.open_output(skypy.get_extra_output_indices()[0]) as log_out:
        pickle.dump(events, log_out)
github mrry / ciel / src / python / skypy / c_pipe_streamer.py View on Github external
n_chunks = int(n_chunks)
    
    producer = skypy.spawn_exec("proc", command="/local/scratch/cs448/skywriting/src/c/tests/stream_producer", force_n_outputs=2, proc_pargs=[n_chunks, producer_may_stream, producer_pipe])

    consumer_input = producer[1]

    consumer_out = skypy.spawn_exec("proc", command="/local/scratch/cs448/skywriting/src/c/tests/stream_consumer", force_n_outputs=1, proc_pargs=[consumer_input, consumer_may_stream, consumer_pipe, consumer_must_block])
    
    ret_outs = [consumer_out, producer[0]]
    
    with skypy.RequiredRefs(ret_outs):
    
        with skypy.deref_as_raw_file(consumer_out) as fp:
            consumer_report = fp.read()
        with skypy.deref_as_raw_file(producer[0]) as fp:
            producer_report = fp.read()

    return "Producer reports: %s, Consumer reports: %s" % (producer_report, consumer_report)
github mrry / ciel / src / python / skypy / c_pipe_streamer.py View on Github external
else:
        raise Exception("pipe_streamer.py: Argument 4 must be boolean (got %s)" % do_log)

    n_chunks = int(n_chunks)
    
    producer = skypy.spawn_exec("proc", command="/local/scratch/cs448/skywriting/src/c/tests/stream_producer", force_n_outputs=2, proc_pargs=[n_chunks, producer_may_stream, producer_pipe])

    consumer_input = producer[1]

    consumer_out = skypy.spawn_exec("proc", command="/local/scratch/cs448/skywriting/src/c/tests/stream_consumer", force_n_outputs=1, proc_pargs=[consumer_input, consumer_may_stream, consumer_pipe, consumer_must_block])
    
    ret_outs = [consumer_out, producer[0]]
    
    with skypy.RequiredRefs(ret_outs):
    
        with skypy.deref_as_raw_file(consumer_out) as fp:
            consumer_report = fp.read()
        with skypy.deref_as_raw_file(producer[0]) as fp:
            producer_report = fp.read()

    return "Producer reports: %s, Consumer reports: %s" % (producer_report, consumer_report)
github mrry / ciel / src / python / skypy / example_producer.py View on Github external
def stream_consumer(chunk_size, in_ref):

    bytes_read = 0

    with skypy.deref_as_raw_file(in_ref, may_stream=True, chunk_size=chunk_size) as in_file:
        while True:
            str = in_file.read(4096)
            bytes_read += len(str)
            if len(str) == 0:
                break

    return "Read %d bytes" % bytes_read
github mrry / ciel / src / python / skypy / pipe_streamer.py View on Github external
def stream_link(chunk_size, input_ref, may_stream, producer_pipe, consumer_pipe, must_block):

    bytes_written = 0

    # Convoluted structure to avoid blocking on a ref whilst we've got an output in progress
    with skypy.open_output(skypy.get_extra_output_indices()[0], may_stream=may_stream, may_pipe=producer_pipe) as out_file:
        with skypy.deref_as_raw_file(input_ref, may_stream=may_stream, sole_consumer=consumer_pipe, chunk_size=chunk_size, must_block=must_block) as in_file:
            while True:
                buf = in_file.read(4096)
                if len(buf) == 0:
                    break
                out_file.write(buf)
                bytes_written += len(buf)

    return "Read/wrote %d bytes" % bytes_written
github mrry / ciel / src / python / skypy / c_pipe_streamer.py View on Github external
def stream_consumer(chunk_size, in_ref, may_stream, use_direct_pipes, must_block, do_log):

    bytes_read = 0
    next_threshold = chunk_size
    
    events = []
    events.append(("STARTED", datetime.now()))

    with skypy.deref_as_raw_file(in_ref, may_stream=may_stream, sole_consumer=use_direct_pipes, chunk_size=chunk_size, must_block=must_block, debug_log=do_log) as in_file:

        events.append(("START_READ", datetime.now()))
    
        while True:
            str = in_file.read(4096)
            bytes_read += len(str)
            if len(str) == 0:
                break
            if bytes_read >= next_threshold:
                next_threshold += chunk_size
                events.append(("READ_CHUNK", datetime.now()))
        try:
            events.extend(in_file.debug_log)
        except:
            pass
github mrry / ciel / src / python / skypy / stream_consumer.py View on Github external
def skypy_main(run_seconds, async, direct):
    
    if async.find("true") != -1:
        may_stream = True
    else:
        may_stream = False
    if direct.find("true") != -1:
        try_direct = True
    else:
        try_direct = False
    tests_jar = skypy.package_lookup("java_tests")
    refs = skypy.spawn_exec("java", args={"inputs": [], "argv": [str(run_seconds)], "lib": [tests_jar], "class": "tests.JitteryProducer", "stream_output": True, "pipe_output": try_direct}, n_outputs=2)

    got_bytes = 0

    with skypy.deref_as_raw_file(refs[0], may_stream=may_stream, sole_consumer=try_direct, chunk_size=1048576) as file_in:
        while True:
            file_str = file_in.read(1048576)
            if len(file_str) == 0:
                break
            print >>sys.stderr, "Read", len(file_str), "bytes"
            got_bytes += len(file_str)
    with skypy.deref_as_raw_file(refs[1]) as n_bytes:
        byte_count = n_bytes.read()

    return "Producer wrote %s, I got %d starting with %s" % (byte_count, got_bytes, file_str[:20])