Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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():
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 kmeans_reduce(reduce_input):
result = java("skywriting.examples.skyhout.kmeans.KMeansReduceTask",
reduce_input + [old_clusters],
[convergenceDelta],
jar_lib,
2)
return {"cluster" : result[0], "converged" : skypy.deref(result[1])}
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))
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)