首页 > 解决方案 > 无法将 Ray Serve HTTP 代理绑定到“127.0.0.1:8000”

问题描述

使用以下命令启动 Ray Head 节点:

ray start \
       --head \
       --port=6379 \
       --object-manager-port=8076 \
     --include-dashboard=true \
       --dashboard-host=0.0.0.0 \
      --dashboard-port=8266

输出:

local node IP: localhost
2021-07-10 20:58:01,607 INFO services.py:1245 -- View the Ray dashboard at http://localhost:8266

--------------------
Ray runtime started.
--------------------

Next steps
  To connect to this Ray runtime from another node, run
    ray start --address='localhost:PORT' --redis-password='xxxx'
  
  Alternatively, use the following Python code:
    import ray
    ray.init(address='auto', _redis_password='xxxx')
  
  If connection fails, check your firewall settings and network configuration.
  
  To terminate the Ray runtime, run
    ray stop

之后在fastapi上写了一段小python代码:

import ray
from ray import serve

from fastapi import FastAPI

app = FastAPI()

serve_handle = None

@app.on_event("startup") # Code to be run when the server starts.
async def startup_event():
    ray.init(address='auto', _redis_password='xxxx')
    client = serve.start()
    for _ in range(100):
        x.append(1)
    print(x)

但是当我用命令运行脚本时:

uvicorn py_code:app

出现以下错误:

ValueError: Failed to bind Ray Serve HTTP proxy to '127.0.0.1:8000'.
Please make sure your http-host and http-port are specified correctly.

有人可以解释一下我怎样才能让它工作。谢谢

标签: pythonfastapiray

解决方案


推荐阅读