error: [Errno 98] Address already in use
error: [Errno 98] Address already in use
我正在创建一个简单的 flaskapp,我将在 heroku 上部署它,这是我第一次在 heroku 上部署 python 应用程序,也就是说我是 gunicorn 的新手。
补充说明:使用虚拟环境。
flask版本Flask==0.10.1
gunicorn==19.3.0
使用 'python run.py' 有效
使用'foreman start'我得到以下错误
16:35:44 web.1 | started with pid 4047
16:35:44 web.1 | [2015-03-30 16:35:44 +0000] [4047] [INFO] Starting gunicorn 19.3.0
16:35:44 web.1 | [2015-03-30 16:35:44 +0000] [4047] [INFO] Listening at: http://0.0.0.0:5000 (4047)
16:35:44 web.1 | [2015-03-30 16:35:44 +0000] [4047] [INFO] Using worker: sync
16:35:44 web.1 | [2015-03-30 16:35:44 +0000] [4053] [INFO] Booting worker with pid: 4053
16:35:44 web.1 | * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
16:35:44 web.1 | [2015-03-30 16:35:44 +0000] [4053] [ERROR] Exception in worker process:
16:35:44 web.1 | Traceback (most recent call last):
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
16:35:44 web.1 | worker.init_process()
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
16:35:44 web.1 | self.wsgi = self.app.wsgi()
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
16:35:44 web.1 | self.callable = self.load()
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
16:35:44 web.1 | return self.load_wsgiapp()
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
16:35:44 web.1 | return util.import_app(self.app_uri)
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
16:35:44 web.1 | __import__(module)
16:35:44 web.1 | File "/home/adminuser/Desktop/Github/SoftwareEng/barcodeServer/SoftwareEng/run.py", line 3, in <module>
16:35:44 web.1 | flaskapp.run(debug=True)
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/flask/app.py", line 772, in run
16:35:44 web.1 | run_simple(host, port, self, **options)
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/werkzeug/serving.py", line 617, in run_simple
16:35:44 web.1 | test_socket.bind((hostname, port))
16:35:44 web.1 | File "/usr/lib/python2.7/socket.py", line 224, in meth
16:35:44 web.1 | return getattr(self._sock,name)(*args)
16:35:44 web.1 | error: [Errno 98] Address already in use
16:35:44 web.1 | Traceback (most recent call last):
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
16:35:44 web.1 | worker.init_process()
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
16:35:44 web.1 | self.wsgi = self.app.wsgi()
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
16:35:44 web.1 | self.callable = self.load()
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
16:35:44 web.1 | return self.load_wsgiapp()
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
16:35:44 web.1 | return util.import_app(self.app_uri)
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
16:35:44 web.1 | __import__(module)
16:35:44 web.1 | File "/home/adminuser/Desktop/Github/SoftwareEng/barcodeServer/SoftwareEng/run.py", line 3, in <module>
16:35:44 web.1 | flaskapp.run(debug=True)
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/flask/app.py", line 772, in run
16:35:44 web.1 | run_simple(host, port, self, **options)
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/werkzeug/serving.py", line 617, in run_simple
16:35:44 web.1 | test_socket.bind((hostname, port))
16:35:44 web.1 | File "/usr/lib/python2.7/socket.py", line 224, in meth
16:35:44 web.1 | return getattr(self._sock,name)(*args)
16:35:44 web.1 | error: [Errno 98] Address already in use
16:35:44 web.1 | [2015-03-30 16:35:44 +0000] [4053] [INFO] Worker exiting (pid: 4053)
16:35:44 web.1 | [2015-03-30 16:35:44 +0000] [4047] [INFO] Shutting down: Master
16:35:44 web.1 | [2015-03-30 16:35:44 +0000] [4047] [INFO] Reason: Worker failed to boot.
16:35:44 web.1 | exited with code 3
16:35:44 system | sending SIGTERM to all processes
Procfile
web: gunicorn run:flaskapp --log-file=-
文件结构
/
...
run.py
Procfile
app/
__init__.py
routes.py
...
run.py
from app import flaskapp
flaskapp.run(debug=True)
__init__.py
from flask import Flask
flaskapp = Flask(__name__)
from app import routes
routes.py
from app import flaskapp
from flask import render_template
import dbwrapper
@flaskapp.route('/')
@flaskapp.route('/home')
def index():
return render_template('home.html')
根据我的阅读,gunicorn 允许创建多个线程,这让我认为线程正在尝试访问同一个端口,这会引发 already in use 错误 .但是我不知道如何解决它,我们将不胜感激。
看起来您正在调用 run:flaskapp 而不是 app:flaskapp 并且 run.py 正在尝试打开另一个实例。
16:35:44 web.1 | File "/home/adminuser/Desktop/Github/SoftwareEng/barcodeServer/SoftwareEng/run.py", line 3, in <module>
首先,始终封装 运行:
if __name__ == '__main__':
flaskapp.run(debug=True)
并更新您的 procfile 以调用 app.__init__.py
:
web: gunicorn app:flaskapp --log-file=-
PS:我不知道 procfile 或 foreman 是什么 -- heroku 东西?
我正在创建一个简单的 flaskapp,我将在 heroku 上部署它,这是我第一次在 heroku 上部署 python 应用程序,也就是说我是 gunicorn 的新手。
补充说明:使用虚拟环境。
flask版本Flask==0.10.1
gunicorn==19.3.0
使用 'python run.py' 有效
使用'foreman start'我得到以下错误
16:35:44 web.1 | started with pid 4047
16:35:44 web.1 | [2015-03-30 16:35:44 +0000] [4047] [INFO] Starting gunicorn 19.3.0
16:35:44 web.1 | [2015-03-30 16:35:44 +0000] [4047] [INFO] Listening at: http://0.0.0.0:5000 (4047)
16:35:44 web.1 | [2015-03-30 16:35:44 +0000] [4047] [INFO] Using worker: sync
16:35:44 web.1 | [2015-03-30 16:35:44 +0000] [4053] [INFO] Booting worker with pid: 4053
16:35:44 web.1 | * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
16:35:44 web.1 | [2015-03-30 16:35:44 +0000] [4053] [ERROR] Exception in worker process:
16:35:44 web.1 | Traceback (most recent call last):
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
16:35:44 web.1 | worker.init_process()
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
16:35:44 web.1 | self.wsgi = self.app.wsgi()
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
16:35:44 web.1 | self.callable = self.load()
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
16:35:44 web.1 | return self.load_wsgiapp()
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
16:35:44 web.1 | return util.import_app(self.app_uri)
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
16:35:44 web.1 | __import__(module)
16:35:44 web.1 | File "/home/adminuser/Desktop/Github/SoftwareEng/barcodeServer/SoftwareEng/run.py", line 3, in <module>
16:35:44 web.1 | flaskapp.run(debug=True)
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/flask/app.py", line 772, in run
16:35:44 web.1 | run_simple(host, port, self, **options)
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/werkzeug/serving.py", line 617, in run_simple
16:35:44 web.1 | test_socket.bind((hostname, port))
16:35:44 web.1 | File "/usr/lib/python2.7/socket.py", line 224, in meth
16:35:44 web.1 | return getattr(self._sock,name)(*args)
16:35:44 web.1 | error: [Errno 98] Address already in use
16:35:44 web.1 | Traceback (most recent call last):
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
16:35:44 web.1 | worker.init_process()
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
16:35:44 web.1 | self.wsgi = self.app.wsgi()
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
16:35:44 web.1 | self.callable = self.load()
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
16:35:44 web.1 | return self.load_wsgiapp()
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
16:35:44 web.1 | return util.import_app(self.app_uri)
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
16:35:44 web.1 | __import__(module)
16:35:44 web.1 | File "/home/adminuser/Desktop/Github/SoftwareEng/barcodeServer/SoftwareEng/run.py", line 3, in <module>
16:35:44 web.1 | flaskapp.run(debug=True)
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/flask/app.py", line 772, in run
16:35:44 web.1 | run_simple(host, port, self, **options)
16:35:44 web.1 | File "/home/adminuser/Desktop/test/SoftwareEng/local/lib/python2.7/site-packages/werkzeug/serving.py", line 617, in run_simple
16:35:44 web.1 | test_socket.bind((hostname, port))
16:35:44 web.1 | File "/usr/lib/python2.7/socket.py", line 224, in meth
16:35:44 web.1 | return getattr(self._sock,name)(*args)
16:35:44 web.1 | error: [Errno 98] Address already in use
16:35:44 web.1 | [2015-03-30 16:35:44 +0000] [4053] [INFO] Worker exiting (pid: 4053)
16:35:44 web.1 | [2015-03-30 16:35:44 +0000] [4047] [INFO] Shutting down: Master
16:35:44 web.1 | [2015-03-30 16:35:44 +0000] [4047] [INFO] Reason: Worker failed to boot.
16:35:44 web.1 | exited with code 3
16:35:44 system | sending SIGTERM to all processes
Procfile
web: gunicorn run:flaskapp --log-file=-
文件结构
/
...
run.py
Procfile
app/
__init__.py
routes.py
...
run.py
from app import flaskapp
flaskapp.run(debug=True)
__init__.py
from flask import Flask
flaskapp = Flask(__name__)
from app import routes
routes.py
from app import flaskapp
from flask import render_template
import dbwrapper
@flaskapp.route('/')
@flaskapp.route('/home')
def index():
return render_template('home.html')
根据我的阅读,gunicorn 允许创建多个线程,这让我认为线程正在尝试访问同一个端口,这会引发 already in use 错误 .但是我不知道如何解决它,我们将不胜感激。
看起来您正在调用 run:flaskapp 而不是 app:flaskapp 并且 run.py 正在尝试打开另一个实例。
16:35:44 web.1 | File "/home/adminuser/Desktop/Github/SoftwareEng/barcodeServer/SoftwareEng/run.py", line 3, in <module>
首先,始终封装 运行:
if __name__ == '__main__':
flaskapp.run(debug=True)
并更新您的 procfile 以调用 app.__init__.py
:
web: gunicorn app:flaskapp --log-file=-
PS:我不知道 procfile 或 foreman 是什么 -- heroku 东西?