def skypy_main(): ret = skypy.spawn(lambda i: "Child returns %d" % i, 1) skypy.deref(ret) ret = skypy.spawn(lambda i: "Child returns %d" % i, 2) skypy.deref(ret) return 5
def skypy_main(): sys.stderr.write("Main start\n") ref = skypy.spawn(lambda: spawnee(8)) answer = skypy.deref(ref) sys.stderr.write("Final result: %d\n" % answer) return answer
def skypy_main(): sys.stderr.write("Main start\n"); ref = skypy.spawn(lambda: spawnee(8)) answer = skypy.deref(ref) sys.stderr.write("Final result: %d\n" % answer) return answer
def skypy_main(): spawned = [skypy.spawn(lambda: spawnee(i)) for i in range(10)] spawn_rets = dict() 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))
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
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)] results = [skypy.deref(x) for x in spawnees] accum = 0 for result in results: accum += result return accum
def skypy_main(): print >> sys.stderr, "SkyPy example producer:", len( skypy.extra_outputs), "outputs" # Step 1: Test writing our external raw outputs. for i, id in enumerate(skypy.extra_outputs): 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): name = skypy.get_fresh_output_name() file_out = skypy.open_output(name) 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, 262144, 100, n_extra_outputs=1) consumer_out = skypy.spawn(stream_consumer, 262144, producer.extra_outputs[0]) ret_outs = [producer.ret_output, 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)
def skypy_main(): print >>sys.stderr, "SkyPy example producer:", len(skypy.extra_outputs), "outputs" # Step 1: Test writing our external raw outputs. for i, id in enumerate(skypy.extra_outputs): 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): name = skypy.get_fresh_output_name() file_out = skypy.open_output(name) 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, 262144, 100, n_extra_outputs=1) consumer_out = skypy.spawn(stream_consumer, 262144, producer.extra_outputs[0]) ret_outs = [producer.ret_output, 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)
def skypy_main(n_links, n_chunks, mode): if mode == "sync": producer_pipe = False consumer_pipe = False consumer_must_block = False producer_may_stream = False consumer_may_stream = False elif mode == "indirect_single_fetch": producer_pipe = False consumer_pipe = False consumer_must_block = False producer_may_stream = False consumer_may_stream = True elif mode == "indirect_pipe": producer_pipe = False consumer_pipe = False consumer_must_block = True producer_may_stream = True consumer_may_stream = True elif mode == "indirect": producer_pipe = False consumer_pipe = False consumer_must_block = False producer_may_stream = True consumer_may_stream = True elif mode == "indirect_tcp": producer_pipe = False consumer_pipe = True consumer_must_block = False producer_may_stream = True consumer_may_stream = True elif mode == "direct": producer_pipe = True consumer_pipe = True consumer_must_block = False producer_may_stream = True consumer_may_stream = True else: raise Exception("pipe_streamer.py: bad mode %s" % mode) n_links = int(n_links) n_chunks = int(n_chunks) producer = skypy.spawn(stream_producer, 67108864, n_chunks, producer_may_stream, producer_pipe, n_extra_outputs=2) links_out = [] for i in range(n_links): if i == 0: input_ref = producer[1] else: input_ref = links_out[-1][1] links_out.append(skypy.spawn(stream_link, 67108864, input_ref, producer_may_stream, producer_pipe, consumer_pipe, consumer_must_block, extra_dependencies=[input_ref], n_extra_outputs=1)) 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]]
def skypy_main(): wc_input = skypy.spawn(lambda: chargen(1000000)) wc_result = skypy.sync_exec("stdinout", {"inputs": [wc_input], "command_line":["wc", "-c"]}, 1) return skypy.deref_json(wc_result[0])