mirror of
https://github.com/vale981/ray
synced 2025-03-07 02:51:39 -05:00

This PR makes a number of major overhauls to the Ray core docs: Add a key-concepts section for {Tasks, Actors, Objects, Placement Groups, Env Deps}. Re-org the user guide to align with key concepts. Rewrite the walkthrough to link to mini-walkthroughs in the key concept sections. Minor tweaks and additional transition material.
36 lines
816 B
Python
36 lines
816 B
Python
import ray
|
|
import time
|
|
|
|
|
|
# A regular Python function.
|
|
def normal_function():
|
|
return 1
|
|
|
|
|
|
# By adding the `@ray.remote` decorator, a regular Python function
|
|
# becomes a Ray remote function.
|
|
@ray.remote
|
|
def my_function():
|
|
return 1
|
|
|
|
|
|
# To invoke this remote function, use the `remote` method.
|
|
# This will immediately return an object ref (a future) and then create
|
|
# a task that will be executed on a worker process.
|
|
obj_ref = my_function.remote()
|
|
|
|
# The result can be retrieved with ``ray.get``.
|
|
assert ray.get(obj_ref) == 1
|
|
|
|
|
|
@ray.remote
|
|
def slow_function():
|
|
time.sleep(10)
|
|
return 1
|
|
|
|
|
|
# Invocations of Ray remote functions happen in parallel.
|
|
# All computation is performed in the background, driven by Ray's internal event loop.
|
|
for _ in range(4):
|
|
# This doesn't block.
|
|
slow_function.remote()
|