Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

250
Views
Flask genera `Dirección ya en uso` ejecutándose con un servidor WSGI como Gunicorn

Estoy tratando de ejecutar mi aplicación con Gunicorn. Sin embargo, Flask genera OSError: [Errno 98] Address already in use mientras se inicia Gunicorn, luego Gunicorn se apaga. ¿Cómo sirvo la aplicación con 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.

Probé gunicorn Connection en uso para Python Flass y error: [Errno 98] La dirección ya está en uso pero no pude hacer que funcionara.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Está utilizando Gunicorn (o cualquier servidor WSGI de producción), por lo que no desea utilizar el servidor de desarrollo Flask. Pero estás llamando a app.run incondicionalmente. Gunicorn se inicia, vincula la dirección, luego importa su aplicación, que llama a app.run e intenta iniciar su propio servidor. Pero la dirección ya está en uso por Gunicorn.

Mueva app.run a un bloque de protección:

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

O, preferiblemente, elimínelo por completo, ya que debería usar el comando flask para ejecutar el servidor de desarrollo, como se describe en los documentos .

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!