Skip to content

Instantly share code, notes, and snippets.

@robertnishihara
Created February 11, 2019 04:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertnishihara/23173a264206623347ade31ea44f4dc5 to your computer and use it in GitHub Desktop.
Save robertnishihara/23173a264206623347ade31ea44f4dc5 to your computer and use it in GitHub Desktop.
import ray
import time
# Start Ray.
ray.init()
@ray.remote
def f(x):
time.sleep(1)
return x
# Start 4 tasks in parallel.
result_ids = []
for i in range(4):
result_ids.append(f.remote(i))
# Wait for the tasks to complete and retrieve the results.
# With at least 4 cores, this will take 1 second.
results = ray.get(result_ids) # [0, 1, 2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment