-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: owenowenisme <[email protected]>
- Loading branch information
1 parent
d705cef
commit 4a952cb
Showing
3 changed files
with
137 additions
and
15 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
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,21 @@ | ||
import ray | ||
import sys | ||
|
||
ray.init(namespace=sys.argv[1]) | ||
|
||
@ray.remote | ||
class TestCounter: | ||
def __init__(self): | ||
self.value = 0 | ||
|
||
def increment(self): | ||
self.value += 1 | ||
return self.value | ||
|
||
tc = TestCounter.options(name="testCounter", lifetime="detached", max_restarts=-1).remote() | ||
val1 = ray.get(tc.increment.remote()) | ||
val2 = ray.get(tc.increment.remote()) | ||
print(f"val1: {val1}, val2: {val2}") | ||
|
||
assert(val1 == 1) | ||
assert(val2 == 2) |
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,35 @@ | ||
import ray | ||
import time | ||
import sys | ||
|
||
def retry_with_timeout(func, timeout=90): | ||
err = None | ||
start = time.time() | ||
i = 0 | ||
while time.time() - start <= timeout: | ||
try: | ||
print(f"retry iter: {i}", flush=True) | ||
i += 1 | ||
return func() | ||
except BaseException as e: | ||
err = e | ||
finally: | ||
time.sleep(1) | ||
raise err | ||
|
||
def get_detached_actor(): | ||
return ray.get_actor("testCounter") | ||
|
||
# Try to connect to Ray cluster. | ||
print("Try to connect to Ray cluster.", flush=True) | ||
retry_with_timeout(lambda: ray.init(address='ray://127.0.0.1:10001', namespace=sys.argv[1]), timeout = 180) | ||
|
||
# Get TestCounter actor | ||
print("Get TestCounter actor.", flush=True) | ||
tc = retry_with_timeout(get_detached_actor) | ||
|
||
print("Try to call remote function \'increment\'.", flush=True) | ||
val = retry_with_timeout(lambda: ray.get(tc.increment.remote())) | ||
print(f"val: {val}", flush=True) | ||
|
||
assert(val == int(sys.argv[2])) |