ray/doc/source/serve/doc_code/deploying_serve_example.py
Sihan Wang 786c7f45cf
[Serve][Doc] Update the doc code to use new api (#27689)
Co-authored-by: Archit Kulkarni <architkulkarni@users.noreply.github.com>
2022-08-11 11:24:17 -05:00

52 lines
1,018 B
Python

import subprocess
# __deploy_in_single_file_1_start__
import ray
from ray import serve
@serve.deployment
def my_func(request):
return "hello"
serve.run(my_func.bind())
# __deploy_in_single_file_1_end__
serve.shutdown()
ray.shutdown()
subprocess.check_output(["ray", "stop", "--force"])
subprocess.check_output(["ray", "start", "--head"])
# __deploy_in_single_file_2_start__
# This will connect to the running Ray cluster.
ray.init(address="auto", namespace="serve")
@serve.deployment
def my_func(request):
return "hello"
serve.run(my_func.bind())
# __deploy_in_single_file_2_end__
serve.shutdown()
ray.shutdown()
subprocess.check_output(["ray", "stop", "--force"])
subprocess.check_output(["ray", "start", "--head"])
# __deploy_in_k8s_start__
# Connect to the running Ray cluster.
ray.init(address="auto")
@serve.deployment(route_prefix="/hello")
def hello(request):
return "hello world"
serve.run(hello.bind())
# __deploy_in_k8s_end__
subprocess.check_output(["ray", "stop", "--force"])