运行:
1 | gunicorn app:app -c gunicorn.conf.py |
1 | gunicorn.conf.py脚本文件 |
1 2 3 | workers = 5 # 定义同时开启的处理请求的进程数量,根据网站流量适当调整 worker_class = "gevent" # 采用gevent库,支持异步处理请求,提高吞吐量 bind = "0.0.0.0:8888" # 监听IP放宽,以便于Docker之间、Docker和宿主机之间的通信 |
报错信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | Error: class uri 'gevent' invalid or not found: [Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/gunicorn/util.py", line 134, in load_class mod = import_module('.'.join(components)) File "/Library/Frameworks/Python.framework/Versions/3.7/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 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 724, in exec_module File "<frozen importlib._bootstrap_external>", line 860, in get_code File "<frozen importlib._bootstrap_external>", line 791, in source_to_code File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/gunicorn/workers/ggevent.py", line 30 from gunicorn.workers.async import AsyncWorker ^ SyntaxError: invalid syntax ] |
解决办法:低版本问题,重新安装最新版本。
pip3 uninstall gunicorn 或者sudo pip3 uninstall gunicorn
pip3 install gunicron
再次运行:
1 | gunicorn app:app -c gunicorn.conf.py |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Error: class uri 'gevent' invalid or not found: [Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/gunicorn/util.py", line 99, in load_class mod = importlib.import_module('.'.join(components)) File "/Library/Frameworks/Python.framework/Versions/3.7/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 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 728, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/gunicorn/workers/ggevent.py", line 20, in <module> raise RuntimeError("gevent worker requires gevent 1.4 or higher") RuntimeError: gevent worker requires gevent 1.4 or higher |
错误提示gevent版本过低,要求1.4或者更改版本。
同样卸载重新安装最新版本
pip3 uninstall gevent
pip3 install gevent
再次运行:
1 | gunicorn app:app -c gunicorn.conf.py |
从日志看启动成功
1 2 3 4 5 6 7 8 | [2020-06-07 09:48:51 +0800] [40282] [INFO] Starting gunicorn 20.0.4 [2020-06-07 09:48:51 +0800] [40282] [INFO] Listening at: http://0.0.0.0:8888 (40282) [2020-06-07 09:48:51 +0800] [40282] [INFO] Using worker: gevent [2020-06-07 09:48:51 +0800] [40285] [INFO] Booting worker with pid: 40285 [2020-06-07 09:48:51 +0800] [40290] [INFO] Booting worker with pid: 40290 [2020-06-07 09:48:51 +0800] [40291] [INFO] Booting worker with pid: 40291 [2020-06-07 09:48:51 +0800] [40292] [INFO] Booting worker with pid: 40292 [2020-06-07 09:48:51 +0800] [40293] [INFO] Booting worker with pid: 40293 |
