9
我正在創建一個簡單的flaskapp,我將在heroku上部署,第一次在heroku上部署python應用程序,並說那是我對gunicorn的新手。錯誤:[Errno 98]地址已在使用
附加註釋:使用虛擬環境。
瓶瓶== 0.10.1
gunicorn == 19.3.0
使用 '蟒蛇run.py' 工作
使用 '工頭開始' 我得到的版本如下錯誤
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允許創建多個線程,這導致我認爲線程試圖訪問相同的端口引發已在使用錯誤。但我不知道如何解決它,任何幫助表示讚賞。
procfile是一個文件,用於指定你想運行的命令 最好說[這裏](http://stackoverflow.com/questions/18670186/launching-an-app-in-heroku-what-is -procfile-web-command) 工頭專用於我爲heroku安裝的toolbelt,它使用procfile啓動應用程序 – 2015-03-30 21:35:12
。請讓我知道建議的修復是否解決了這個問題。 – Jonathan 2015-03-30 21:37:27
我只需要添加 如果\ __ name \ __ =='\ __ main \ __': 它的工作原理,非常感謝 – 2015-03-30 21:44:20