forked from ray-project/ray
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Serve] [Docs] Document Ray object ref serialization (ray-project#42748)
This change documents how to serialize and deserialize object refs in Ray. Link to updated docs: https://anyscale-ray--42748.com.readthedocs.build/en/42748/ray-core/objects/serialization.html#object-refs --------- Signed-off-by: Shreyas Krishnaswamy <[email protected]> Signed-off-by: shrekris-anyscale <[email protected]> Co-authored-by: Stephanie Wang <[email protected]>
1 parent
423cd67
commit f256fbf
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import ray | ||
from ray import cloudpickle | ||
|
||
FILE = "external_store.pickle" | ||
|
||
ray.init() | ||
|
||
my_dict = {"hello": "world"} | ||
|
||
obj_ref = ray.put(my_dict) | ||
with open(FILE, "wb+") as f: | ||
cloudpickle.dump(obj_ref, f) | ||
|
||
# ObjectRef remains pinned in memory because | ||
# it was serialized with ray.cloudpickle. | ||
del obj_ref | ||
|
||
with open(FILE, "rb") as f: | ||
new_obj_ref = cloudpickle.load(f) | ||
|
||
# The deserialized ObjectRef works as expected. | ||
assert ray.get(new_obj_ref) == my_dict | ||
|
||
# Explicitly free the object. | ||
ray._private.internal_api.free(new_obj_ref) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters