Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python gunicorn无法启动烧瓶_Python_Flask_Gunicorn - Fatal编程技术网

Python gunicorn无法启动烧瓶

Python gunicorn无法启动烧瓶,python,flask,gunicorn,Python,Flask,Gunicorn,我不能从古尼科恩开始。当我输入“gunicorn run:app”时,服务器会给我错误信息。但我检查是否没有使用127.0.0.1:8000的服务。我可以使用“python run.py”来运行这个应用程序 root@ip-172-31-18-230:/var/www/vamk.help/vamk# gunicorn run:app [2016-05-11 02:13:09 +0000] [20288] [INFO] Starting gunicorn 19.4.5 [2016-05-11 02

我不能从古尼科恩开始。当我输入“gunicorn run:app”时,服务器会给我错误信息。但我检查是否没有使用127.0.0.1:8000的服务。我可以使用“python run.py”来运行这个应用程序

root@ip-172-31-18-230:/var/www/vamk.help/vamk# gunicorn run:app
[2016-05-11 02:13:09 +0000] [20288] [INFO] Starting gunicorn 19.4.5
[2016-05-11 02:13:09 +0000] [20288] [INFO] Listening at: http://127.0.0.1:8000 (                                                                                                 20288)
[2016-05-11 02:13:09 +0000] [20288] [INFO] Using worker: sync
[2016-05-11 02:13:09 +0000] [20293] [INFO] Booting worker with pid: 20293
[2016-05-11 02:13:10 +0000] [20293] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 515, i                                                                                                 n spawn_worker
    worker.init_process()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 1                                                                                                 22, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 1                                                                                                 30, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, i                                                                                                 n wsgi
    self.callable = self.load()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 65                                                                                                 , in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52                                                                                                 , in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/util.py", line 357, in i                                                                                                 mport_app
    __import__(module)
  File "/var/www/vamk.help/vamk/run.py", line 3, in <module>
    app.run(threaded=True, debug=app.config['DEBUG'], port=app.config['PORT'])
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 772, in run
    run_simple(host, port, self, **options)
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 677, i                                                                                                 n run_simple
    s.bind((hostname, port))
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 98] Address already in use
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 515, i                                                                                                 n spawn_worker
    worker.init_process()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 1                                                                                                 22, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 1                                                                                                 30, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, i                                                                                                 n wsgi
    self.callable = self.load()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 65                                                                                                 , in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52                                                                                                 , in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/util.py", line 357, in i                                                                                                 mport_app
    __import__(module)
  File "/var/www/vamk.help/vamk/run.py", line 3, in <module>
    app.run(threaded=True, debug=app.config['DEBUG'], port=app.config['PORT'])
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 772, in run
    run_simple(host, port, self, **options)
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 677, i                                                                                                 n run_simple
    s.bind((hostname, port))
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 98] Address already in use

要将flask与gunicorn一起使用,您不必运行应用程序(
app.run()
),因为它是一个仅用于测试的单一阻塞过程

而是将启动变量
app
的flask app模块作为参数传递给gunicorn,而不是外部run.py

这是将gunicorn与烧瓶一起使用的正确方法

gunicorn  -b HOST:PORT <MODULE_NAME>:app
gunicorn-b主机:端口:app

用正确的模块名或文件名替换模块名。使用
-b
标志设置IP地址和端口号。

这对我来说很有效。更改run.py文件,如下所示

from app import app

if __name__ == "__main__":
    app.run(debug=app.config['DEBUG'], port=app.config['PORT'])
from app import app

if __name__ == "__main__":
    app.run(debug=app.config['DEBUG'], port=app.config['PORT'])