Lawouach/WebSocket-for-Python — Issue #18: Exception when running with gevent 1.0
Author: tweber
Created: 2012-01-17 22:49:13+00:00
State: open

When running geventserver with gevent 1.0, exception occurs

Traceback (most recent call last):
File "build/bdist.macosx-10.7-intel/egg/gevent/pywsgi.py", line 449, in handle_one_response
self.run_application()
File "ws4py/server/geventserver.py", line 64, in run_application
self.result = self.application(self.environ, start_response_for_upgrade)
File "ws4py/server/wsgi/middleware.py", line 127, in __call__
start_response("101 Web Socket Hybi Handshake", headers)
File "ws4py/server/geventserver.py", line 54, in start_response_for_upgrade
self.wfile.writelines(towrite)
AttributeError: 'UpgradableWSGIHandler' object has no attribute 'wfile'

gevent.pywsgi.WSGIHandler no longer uses attribute wfile.
Here is my fix:

geventserver.py, line 54

# self.wfile.writelines(towrite)
# self.response_length += sum(len(x) for x in towrite)
self.headers_sent = True # otherwise, write() will send its own headers
for data in towrite:
write(data)