Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

256
Vistas
Flask raises `Address already in use` running with a WSGI server such as Gunicorn

I'm trying to run my app with Gunicorn. However, Flask raises OSError: [Errno 98] Address already in use while Gunicorn is starting, then Gunicorn shuts down. How do I serve the app with Gunicorn?

from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return 'Hello, World!'

app.run(debug=True)
gunicorn app:app
[2017-02-19 21:09:50 -0800] [21965] [INFO] Starting gunicorn 19.6.0
[2017-02-19 21:09:50 -0800] [21965] [INFO] Listening at: http://127.0.0.1:8000 (21965)
[2017-02-19 21:09:50 -0800] [21965] [INFO] Using worker: sync
[2017-02-19 21:09:50 -0800] [21968] [INFO] Booting worker with pid: 21968
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
[2017-02-19 21:09:50 -0800] [21969] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/home/david/.virtualenvs/py36/lib/python3.6/site-packages/gunicorn/arbiter.py", line 557, in spawn_worker
    worker.init_process()
  File "/home/david/.virtualenvs/py36/lib/python3.6/site-packages/gunicorn/workers/base.py", line 126, in init_process
    self.load_wsgi()
  File "/home/david/.virtualenvs/py36/lib/python3.6/site-packages/gunicorn/workers/base.py", line 136, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/home/david/.virtualenvs/py36/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/home/david/.virtualenvs/py36/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/home/david/.virtualenvs/py36/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/home/david/.virtualenvs/py36/lib/python3.6/site-packages/gunicorn/util.py", line 357, in import_app
    __import__(module)
  File "/home/david/Projects/py36/app.py", line 4, in <module>
    app.run(debug=True)
  File "/home/david/.virtualenvs/py36/lib/python3.6/site-packages/flask/app.py", line 841, in run
    run_simple(host, port, self, **options)
  File "/home/david/.virtualenvs/py36/lib/python3.6/site-packages/werkzeug/serving.py", line 691, in run_simple
    s.bind((hostname, port))
OSError: [Errno 98] Address already in use

[2017-02-19 21:09:50 -0800] [21968] [INFO] Worker exiting (pid: 21968)
[2017-02-19 21:09:50 -0800] [21965] [INFO] Shutting down: Master
[2017-02-19 21:09:50 -0800] [21965] [INFO] Reason: Worker failed to boot.

I tried gunicorn Connection in use for python flask and error: [Errno 98] Address already in use but couldn't get it to work.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You're using Gunicorn (or any production WSGI server), so you don't want to use the Flask dev server. But you're calling app.run unconditionally. Gunicorn starts, binds the address, then imports your app, which calls app.run and tries to start its own server. But the address is already in use by Gunicorn.

Move app.run into a guard block:

if __name__ == '__main__':
    app.run()

Or preferably remove it completely, since you should be using the flask command to run the dev server, as described in the docs.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda