I’m building a gRPC Python app and tried to use watchdog
with the watchmedo
extension to listen for code changes and reload, like it is described in this question.
When the server is loaded and I make a change on some file, I can see an exception trace in the docker logs (I added a print('Starting server...')
line for guidance):
Starting server...
Traceback (most recent call last):
File "/code/main.py", line 4, in <module>
serve()
File "/code/app/server.py", line 20, in serve
server.wait_for_termination()
File "/code/.venv/lib/python3.12/site-packages/grpc/_server.py", line 1485, in wait_for_termination
return _common.wait(
^^^^^^^^^^^^^
File "/code/.venv/lib/python3.12/site-packages/grpc/_common.py", line 156, in wait
_wait_once(wait_fn, MAXIMUM_WAIT_TIMEOUT, spin_cb)
File "/code/.venv/lib/python3.12/site-packages/grpc/_common.py", line 116, in _wait_once
wait_fn(timeout=timeout)
File "/usr/local/lib/python3.12/threading.py", line 655, in wait
signaled = self._cond.wait(timeout)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/threading.py", line 359, in wait
gotit = waiter.acquire(True, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt
Starting server...
It seems that it is recognizing the file changes, but in the end it is not refreshing the code.
I’m testing this by adding a unit test that asserts a failure, and then running the tests again. It doesn’t fail.
I’m using poetry
, and my docker-compose.yml
file looks like this:
service:
build: .
depends_on:
postgres:
condition: service_healthy
command: poetry run watchmedo auto-restart -d "/app" -p '*.py' --recursive -- python main.py
volumes:
- .:/app
ports:
- '8010:8010'
the project structure is:
├── app
├── protos
└── main.py
relevant sections of the Dockerfile
:
FROM python:3.12.3-slim-bookworm
RUN pip install poetry==1.8.3
WORKDIR /code
COPY ... ./
RUN poetry install ...
COPY app ./app
COPY protos ./protos
COPY main.py ./
relevant package versions:
[tool.poetry.dependencies]
python = "^3.12"
grpcio = "^1.63.0"
grpcio-tools = "^1.63.0"
watchdog = {extras = ["watchmedo"], version = "^4.0.1"}
Anyone with some grpc experience can help me figure out what is happening?