Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

534
Visualizações
How to enable logging of Flask app with `gevent.pywsgi.WSGIServer` and `WebSocketHandler`?

The issue should be reproducible with the following two minimal examples:

Minimal example with app.run()

from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
    return 'Hello'

app.run()

Minimal example with gevent.pywsgi.WSGIServer

from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
    return 'Hello'

from gevent import pywsgi
from geventwebsocket.handler import WebSocketHandler
server = pywsgi.WSGIServer(('127.0.0.1', 5000), app, handler_class=WebSocketHandler)
server.serve_forever()

The first 5 lines are identical, so both examples only differ in the way they start the server. Both servers do work, I get "Hello" in the browser. The first example prints:

 * Serving Flask app "1" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [20/Jun/2019 23:43:15] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [20/Jun/2019 23:43:19] "GET / HTTP/1.1" 200 -

So the console output shows some information about every request which is handled by the server.

However, with the second example, I don't get any logging output in the console anymore. How do I enable logging for gevent.pywsgi.WSGIServer and WebSocketHandler?


Background (which doesn't matter regarding the issue, I think)

I'm running a Flask app which uses flask_sockets. Because

Werkzeug development server cannot provide the WSGI environ with a websocket interface

I am not able to use the server with app.run() and I'm using gevent.pywsgi.WSGIServer instead. The code of my example above is taken directly from the module's examples at https://github.com/heroku-python/flask-sockets without any modifications.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

It should work like that, but it's a bug in WebSocketHandler from the geventwebsocket module which has already been reported: https://gitlab.com/noppo/gevent-websocket/issues/16

over 4 years ago · Santiago Trujillo Relatório

0

Logging works differently with gevent.pywsgi.WSGIServer. It uses python logging and is much more sophisticated and flexible.

Here's an example:

from gevent import pywsgi
from geventwebsocket.handler import WebSocketHandler

import logging
logging.basicConfig(level=logging.INFO)

server = pywsgi.WSGIServer(('127.0.0.1', 5000), app, handler_class=WebSocketHandler)
server.serve_forever() 

And now wherever you want output, you can do:

logging.info("You can see me now...")   

If you want to see startup info from WSGIServer, then set the log level to DEBUG and you can see tons of output.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda