Esempio n. 1
0
def skypy_main():
    
    new_output_index = skypy.get_fresh_output_index()
    out_fp = skypy.open_output(new_output_index)
    with out_fp:
        for i in range(100000):
            out_fp.write("Whoozit")
    out_ref = out_fp.get_completed_ref()
    first_counter = skypy.spawn(counter, out_ref, extra_dependencies=[out_ref])
    second_counter = skypy.spawn(counter, out_ref, extra_dependencies=[out_ref])
    with skypy.RequiredRefs([first_counter, second_counter]):
        first_result = skypy.deref(first_counter)
        second_result = skypy.deref(second_counter)
    
    return "First counter said", first_result, "and second one said", second_result
    
    
    
Esempio n. 2
0
def skypy_main():

    print >>sys.stderr, "SkyPy example producer:", len(skypy.get_extra_output_indices()), "outputs"

    # Step 1: Test writing our external raw outputs.

    for i, id in enumerate(skypy.get_extra_output_indices()):
        with skypy.open_output(id) as file_out:
            file_out.write("Skypy writing output %d" % i)

    # Step 2: Test writing fresh outputs.

    refs = []

    for i in range(3):
        idx = skypy.get_fresh_output_index()
        file_out = skypy.open_output(idx)
        with file_out:
            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, 16384, 100, n_extra_outputs=1)
    consumer_out = skypy.spawn(stream_consumer, 16384, 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.get_extra_output_indices()), cooked_result, raw_result, results)