Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
201 views
in Technique[技术] by (71.8m points)

python - error: [Errno 98] Address already in use

I'm creating a simple flaskapp which I'm going to deploy on heroku, first time deploying a python app on heroku, with that said i'm new to gunicorn.

Addtitional notes: Using a virtual environment.

Version of flask Flask==0.10.1

gunicorn==19.3.0

Using 'python run.py' works

Using 'foreman start' I get the following error

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=-

File Structure

/
 ...
 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')

From what I read gunicorn allows for the creation of multiple threads, which leads me to think that the threads are trying to access the same port which throws the already in use error. However I have no idea how to resolve it, any help is appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Looks like you're calling run:flaskapp instead of app:flaskapp and run.py is trying to open another instance.

16:35:44 web.1  |   File "/home/adminuser/Desktop/Github/SoftwareEng/barcodeServer/SoftwareEng/run.py", line 3, in <module>

First, always encapsulate the run:

if __name__ == '__main__':
    flaskapp.run(debug=True)

And update your procfile to call the app.__init__.py instead:

web: gunicorn app:flaskapp --log-file=-

PS: I don't know what procfile or foreman are -- heroku things?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...