0

I'm trying to connect Gunicorn to my Django application, by Docker, to serve it as an HTTP server. The build was successful, with no errors. My problem starts in the race. That's the kind of message I get:

[2020-10-01 12:55:18 +0000] [9] [INFO] Starting gunicorn 20.0.4
[2020-10-01 12:55:18 +0000] [9] [INFO] Listening at: http://0.0.0.0:8010 (9)
[2020-10-01 12:55:18 +0000] [9] [INFO] Using worker: sync
[2020-10-01 12:55:18 +0000] [13] [INFO] Booting worker with pid: 13
[2020-10-01 12:55:18 +0000] [13] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 119, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python3.7/site-packages/gunicorn/util.py", line 358, in import_app
    mod = importlib.import_module(module)
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'wsgi'
[2020-10-01 12:55:18 +0000] [13] [INFO] Worker exiting (pid: 13)
[2020-10-01 12:55:18 +0000] [9] [INFO] Shutting down: Master
[2020-10-01 12:55:18 +0000] [9] [INFO] Reason: Worker failed to boot.

I know that there are several issues with this same doubt, but I have not been successful in reading them and would like another point of view. The error says that the WSGI module was not found, and I don't know why it can't find it. I believe it is a PATH problem.

This is my tree:

Myproject
├───.pip_cache
├───.vscode
├───backups
├───general_app
│   ├───migrations
│   │   └───__pycache__
│   └───__pycache__
├───headers
├───sistem
│   └───__pycache__
│   └───wsgi.py
│   └───urls.py
│   └───settings.py
│   └───asgi.py
├───sistema.egg-info
└───app
    ├───migrations
    │   └───__pycache__
    ├───util
    └───__pycache__

And this is my command on docker to run gunicorn:

(cd .. && gunicorn wsgi:app --user www-data --bind 0.0.0.0:8010 --workers 3) &
nginx -g "daemon off;"

I just try to do this:

(cd .. && gunicorn sistem.wsgi:app --user www-data --bind 0.0.0.0:8010 --workers 3) &
nginx -g "daemon off;"

But the error change to:

ModuleNotFoundError: No module named 'sistem'

I don't understand what may be going on.

zangstrell
  • 39
  • 1
  • 6
  • Can you run Nginx and GUnicorn in separate containers? Launching an important thing as an unmonitored background process isn't a best practice. – David Maze Oct 01 '20 at 13:23
  • (I'd guess `cd .. &` – "switch directories, as a separate background process" – doesn't affect the following command, and you need `cd .. && gunicorn ...` instead.) – David Maze Oct 01 '20 at 13:23
  • @David, the only one '&' (I just edited) it was a typo, sorry about that. Yes, I can run them in different containers, but the error with the gunicorn still remains. – zangstrell Oct 01 '20 at 13:31
  • @Guilherme do your folders all have an [`__init__.py`](https://docs.python.org/3/tutorial/modules.html#packages) file? If not, then the folders will not be recognized as python modules. Also [this link](https://stackoverflow.com/questions/448271/what-is-init-py-for) – Ralf Oct 01 '20 at 13:54
  • @Ralf, all my folders have an __init__.py, I think my problem is with the path, because it seems that the gunicorn does not recognize the local wsgi or its existence. But i'm not sure. – zangstrell Oct 01 '20 at 14:01

0 Answers0