Reputation: 63
When I try to start gunicorn with command gunicorn -w 3 run:app
It crashes and gives me this error:
[2021-08-05 08:35:34 +0000] [71840] [INFO] Booting worker with pid: 71840
[2021-08-05 08:35:34 +0000] [71840] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/home/flask/Unmarked/venv/lib/python3.9/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
worker.init_process()
File "/home/flask/Unmarked/venv/lib/python3.9/site-packages/gunicorn/workers/base.py", line 134, in init_process
self.load_wsgi()
File "/home/flask/Unmarked/venv/lib/python3.9/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
self.wsgi = self.app.wsgi()
File "/home/flask/Unmarked/venv/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/home/flask/Unmarked/venv/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
return self.load_wsgiapp()
File "/home/flask/Unmarked/venv/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
return util.import_app(self.app_uri)
File "/home/flask/Unmarked/venv/lib/python3.9/site-packages/gunicorn/util.py", line 359, in import_app
mod = importlib.import_module(module)
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'run'
[2021-08-05 08:35:34 +0000] [71840] [INFO] Worker exiting (pid: 71840)
[2021-08-05 08:35:34 +0000] [71838] [WARNING] Worker with pid 71840 was terminated due to signal 15
[2021-08-05 08:35:34 +0000] [71838] [INFO] Shutting down: Master
[2021-08-05 08:35:34 +0000] [71838] [INFO] Reason: Worker failed to boot.
When I try to run the app with the normal command flask run
It works like a charm.
I believe it has something to do with the structure. But I am not sure because I am very new to flask, gunicorn and nginx:
In the unmarked.py file is this code right now:
import requests
App = Flask(__name__)
@App.route('/', methods=['GET', 'POST'])
def home():
return render_template('welcome.html')
if __name__ == "__main__":
App.run()
How do I make gunicorn run I am clueless.
Upvotes: 0
Views: 4947
Reputation: 2415
The issue is probably with the parameters you pass to gunicorn
. run:app
implies that it needs to take app
from run.py
, but in your case the app
is located in unmarked.py
, so you need to pass the first parameter accordingly.
Also, I suggest to rename App -> app
, since the uppercase names are for classes in Python.
Try
gunicorn -w 3 unmarked:app
Upvotes: 1