How to use the skypy.RequiredRefs 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 / spawn_wait.py View on Github external
def skypy_main():

    spawned = [skypy.spawn(lambda: spawnee(i)) for i in range(10)]
    spawn_rets = dict()
    with skypy.RequiredRefs(spawned):
        for (i, x) in enumerate(spawned):
            spawn_rets[i] = skypy.deref(x)
        for (key, value) in spawn_rets.iteritems():
            sys.stderr.write("Spawned task %d returned %d\n" % (key, value))
github mrry / ciel / src / python / skypy / recursive_spawn_wait.py View on Github external
def spawnee(i):
    sys.stderr.write("Hello from spawnee at layer %d\n" % i)
    if i == 0:
        return 1
    else:
        spawnees = [skypy.spawn(lambda: spawnee(i - 1)) for j in range(2)]
        with skypy.RequiredRefs(spawnees):
            results = [skypy.deref(x) for x in spawnees]
        accum = 0
        for result in results:
            accum += result
        return accum
github mrry / ciel / src / python / skypy / pipe_streamer.py View on Github external
if n_links == 0:
        consumer_input = producer[1]
    else:
        consumer_input = links_out[-1][1]
    if producer_may_stream:
        extra_dependencies = [consumer_input]
    else:
        extra_dependencies = []
    run_fixed = not producer_may_stream
    consumer_out = skypy.spawn(stream_consumer, 67108864, consumer_input, consumer_may_stream, consumer_pipe, consumer_must_block, n_extra_outputs=1, extra_dependencies=extra_dependencies, run_fixed=run_fixed)
    ret_outs = [producer[0]]
    ret_outs.extend([x[0] for x in links_out])
    ret_outs.append(consumer_out[0])
    
    with skypy.RequiredRefs(ret_outs):
        results = [skypy.deref(x) for x in ret_outs]

    return ["The %d streamers' reports are: %s\n" % (n_links + 2, results), producer[2], consumer_out[1]]
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 / c_pipe_streamer.py View on Github external
elif do_log == "false":
        do_log = False
    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
file_out.write("Skypy writing anonymous output %d" % i)
        refs.append(file_out.get_completed_ref())

    # Step 3: Test reading those results back.

    reader_result = skypy.spawn(reader_function, refs, n_extra_outputs=1)
#    cooked_result, raw_result = read_result(reader_result)
    cooked_result, raw_result = "Dummy", "text"

    # Step 4: Test a stream producer/consumer pair.

    producer = skypy.spawn(stream_producer, 262144, 100, n_extra_outputs=1)
    consumer_out = skypy.spawn(stream_consumer, 262144, producer[1])

    ret_outs = [producer[0], consumer_out]
    with skypy.RequiredRefs(ret_outs):
        results = [skypy.deref(x) for x in ret_outs]

    return "I wrote %d external outputs\nI created 3 myself\nThe reader's cooked result was '%s'\n The reader's raw result was '%s'\nFinally the streamers' reports are %s\n" % (len(skypy.extra_outputs), cooked_result, raw_result, results)