unvicorn旧版本的时候,例如0.10.0,利用fastapi和uvicorn搭建服务如图所示:

from fastapi import FastAPI
import uvicorn

app = FastAPI()

@app.post('/detector')
......

if __name__=="__main__":
    uvicorn.run(app=app,host='10.15.72.22',port=8084,reload=True,workers=1)

unvicorn新版本后,出现

WARNING:  You must pass the application as an import string to enable 'reload' or 'workers'

的问题,实际上是调用方式改变了。

我们在detector.py 文件下,启动uvicorn,使用如下命令 

from fastapi import FastAPI
import uvicorn

app = FastAPI()

@app.post('/detector')
......

if __name__=="__main__":       
  uvicorn.run("detector:app",host='10.15.72.22',port=8084,reload=True,workers=1)

detector是文件名 ,app是应用程序实例名字,这样uvicorn就会正确地加载应用程序并启动服务器。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐