[英]How to hot reload grpc-server in python?
I'm developing some python microservices with grpc and i'm using docker for the cassandra database and the microservices.我正在使用 grpc 开发一些 python 微服务,我正在将 docker 用于 cassandra 数据库和微服务。 Is there a way to setup reload on change within docker-compose?
有没有办法在 docker-compose 中设置重新加载更改?
I'm guessing that first I need the code mounted as a volume but I don't see a way to reload on GRPC server like for example flask does.我猜首先我需要将代码安装为卷,但我没有看到像flask那样在GRPC服务器上重新加载的方法。
We use watchdog[watchmedo]
with our grpc services and Docker.我们将
watchdog[watchmedo]
与我们的 grpc 服务和 Docker 一起使用。
Install watchdog or add to your requirements.txt
file安装看门狗或添加到您的
requirements.txt
文件
python -m pip install watchdog[watchmedo]
Then in your docker-compose.yml
add watchmedo auto-restart --recursive --pattern="*.py" --directory="/usr/src/app/" python -- -m app
to your container where --directory
is the directory to where your app is contained inside the docker container, and python -- -m app
is the file that starts your grpc Server.然后在你
docker-compose.yml
添加watchmedo auto-restart --recursive --pattern="*.py" --directory="/usr/src/app/" python -- -m app
到你的容器中--directory
是您的应用程序包含在 docker 容器中的目录,而python -- -m app
是启动您的 grpc 服务器的文件。 In this example the file that starts the server is called app.py
:在此示例中,启动服务器的文件名为
app.py
:
app:
build:
context: ./app/
dockerfile: ./Dockerfile
target: app
command: watchmedo auto-restart --recursive --pattern="*.py" --directory="/usr/src/app/" python -- -m app
volumes:
- ./app/:/usr/src/app/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.