【发布时间】:2021-02-17 08:54:59
【问题描述】:
从 fastapi python 开始。
这就是我的服务器字符串
class Server:
def __init__(self):
self.app = FastAPI()
def runServer(self, host: str, port: int,is_dev:bool):
uvicorn.run(self.app, host=host, port=port,debug=is_dev)
if __name__ == "__main__":
server = Server()
# read the environment variables
host: str = os.environ['host']
port: int = int(os.environ['port'])
is_dev: bool = bool(os.environ['dev'])
server.runServer(host, port, is_dev)
如果我进行任何更改,这会提升服务器但不会在自动重新加载模式下运行。
我试过了
uvicorn.run(self.app, host=host, port=port, reload=is_dev)
我想重新加载不是一个选项,从而导致服务器崩溃。
我尝试在 launch.json 中传递 --reload args,但仍然无法正常工作
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: FastAPI",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/main.py",
"jinja": true,
"args": ["--reload"],
"env": {
"host": "127.0.0.1",
"port": "5555",
"dev": "true"
}
}
]
}
有什么想法吗?我错过了什么吗?
【问题讨论】:
标签: python debugging visual-studio-code fastapi