-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Labels
Description
I'm have a simple WebsocketWSGI server:
@guv.websocket.WebSocketWSGI
def my_handler(ws):
print('INSIDE HANDLER')
while True:
from_browser = ws.wait()
print('>', from_browser)
ws.send("from server:" + from_browser)
# Served by gunicorn with guv.GuvWorker
def main(global_config, **settings):
lgg = logging.getLogger('root')
lgg.info('start')
return my_handler
# Standalone
def serve():
init_standalone()
lgg = logging.getLogger('root')
lgg.info('start')
host = RC.g('server.host')
port = int(RC.g('server.port'))
server_sock = guv.listen((host, port))
guv.wsgi.serve(server_sock, my_handler)
if __name__ == '__main__':
serve()At some point WebSocketWSGI tries to obtain the socket from the WSGI environment. The original code did not work for multiple reasons:
- Key
guv.inputdoes not exist - There's key
wsgi.input - A method
get_sock()does not exist at all, but guv's class Input has propertysock wsgi.inputis set to different objects, depending on whether gunicorn or guv serves.
Please have a look at this diff. Between some debug prints, the two important changes are to force Input to always set the sock (here) and the method how to fetch the socket from environ (here).
I am not sure what the intended behaviour actually should be.