Skip to content

Instantly share code, notes, and snippets.

@robertnishihara
Created February 11, 2019 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertnishihara/6576e95de3d9080b10c5a6a9db7e7f35 to your computer and use it in GitHub Desktop.
Save robertnishihara/6576e95de3d9080b10c5a6a9db7e7f35 to your computer and use it in GitHub Desktop.
@ray.remote
class Counter(object):
def __init__(self):
self.x = 0
def inc(self):
self.x += 1
def get_value(self):
return self.x
# Create an actor process.
c = Counter.remote()
# Check the actor's counter value.
print(ray.get(c.get_value.remote())) # 0
# Increment the counter twice and check the value again.
c.inc.remote()
c.inc.remote()
print(ray.get(c.get_value.remote())) # 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment