Scaling Python with Ray by Karau Holden;Lublinsky Boris;

Scaling Python with Ray by Karau Holden;Lublinsky Boris;

Author:Karau, Holden;Lublinsky, Boris;
Language: eng
Format: epub
Publisher: O'Reilly Media, Incorporated
Published: 2022-12-06T00:00:00+00:00


Example 8-10. Workflow management with virtual actors

from ray import workflow import ray @workflow.virtual_actor class Counter: def __init__(self, init_val): self._val = init_val def incr(self, val=1): self._val += val print(self._val) @workflow.virtual_actor.readonly def value(self): return self._val workflow.init() # Initialize a Counter actor with id="my_counter". counter = Counter.get_or_create("my_counter", 0) # Similar to workflow steps, actor methods support: # - `run()`, which will return the value # - `run_async()`, which will return a ObjectRef counter.incr.run(10) assert counter.value.run() == 10 # Nonblocking execution. counter.incr.run_async(10) counter.incr.run(10) assert 30 == ray.get(counter.value.run_async())



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.