Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--reload not working for docker #3135

Open
ArturHarutunyan opened this issue Dec 29, 2023 · 1 comment
Open

--reload not working for docker #3135

ArturHarutunyan opened this issue Dec 29, 2023 · 1 comment

Comments

@ArturHarutunyan
Copy link

I have a Docker setup running Gunicorn with Uvicorn workers. It's configured to reload on file changes. However, it starts reloading when settings.py is modified but never completes the process.

Docker Configuration:

  actions:
    restart: always
    build:
      context: ./services/actions
      shm_size: '512mb'
    shm_size: '512mb'
    ports:
      - 8082:8080
    volumes:
      - ./services/actions/logs:/app/logs
      - ./services/actions/src:/app/src
      - ./services/actions/api.py:/app/api.py
    env_file:
      - .env
      - .local.env
    command: gunicorn api:app --workers $ACTION_WORKERS_COUNT --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:$ACTION_PORT --timeout 600 --log-level debug --max-requests 0 --reload --reload-engine=inotify

Logs

[2023-12-29 10:51:56 +0000] [424] [INFO] Worker reloading: settings.py modified
[2023-12-29 10:51:56 +0000] [422] [INFO] Worker reloading: settings.py modified
[2023-12-29 10:51:56 +0000] [423] [INFO] Worker reloading: settings.py modified
[2023-12-29 10:51:56 +0000] [421] [INFO] Worker reloading: settings.py modified

Any insights on why the reloading process isn't completing would be greatly appreciated.

@sylt
Copy link

sylt commented Feb 19, 2024

Seems to be tied to the UvicornWorker worker class, as e.g. sync seems to work fine. The following patch would fix it for uvicorn workers though:

diff --git a/gunicorn/workers/base.py b/gunicorn/workers/base.py
index f97d923c..348d27cc 100644
--- a/gunicorn/workers/base.py
+++ b/gunicorn/workers/base.py
@@ -125,7 +125,8 @@ class Worker(object):
                 os.write(self.PIPE[1], b"1")
                 self.cfg.worker_int(self)
                 time.sleep(0.1)
-                sys.exit(0)
+                import _thread
+                _thread.interrupt_main()
 
             reloader_cls = reloader_engines[self.cfg.reload_engine]
             self.reloader = reloader_cls(extra_files=self.cfg.reload_extra_files,

... but some more investigation as to exactly why it happens would probably be good before submitting any PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants