我正在尝试获取我的瓶子服务器,以便当游戏中的一个人退出时,每个人都可以立即看到它。当我使用长轮询时,所有用户都打开了一个请求。
我遇到的问题是捕获当用户从无法再连接到页面的长轮询中离开页面时引发的异常。错误信息在这里。
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/gevent/pywsgi.py", line 438, in handle_one_response
self.run_application()
File "/usr/lib/python2.7/dist-packages/gevent/pywsgi.py", line 425, in run_application
self.process_result()
File "/usr/lib/python2.7/dist-packages/gevent/pywsgi.py", line 416, in process_result
self.write(data)
File "/usr/lib/python2.7/dist-packages/gevent/pywsgi.py", line 373, in write
self.socket.sendall(msg)
File "/usr/lib/python2.7/dist-packages/gevent/socket.py", line 509, in sendall
data_sent += self.send(_get_memory(data, data_sent), flags)
File "/usr/lib/python2.7/dist-packages/gevent/socket.py", line 483, in send
return sock.send(data, flags)
error: [Errno 32] Broken pipe
<WSGIServer fileno=3 address=0.0.0.0:8080>: Failed to handle request:
request = GET /refreshlobby/1 HTTP/1.1 from ('127.0.0.1', 53331)
application = <bottle.Bottle object at 0x7f9c05672750>
127.0.0.1 - - [2013-07-07 10:59:30] "GET /refreshlobby/1 HTTP/1.1" 200 160 6.038377
处理该页面的函数就是这个。
@route('/refreshlobby/<id>')
def refreshlobby(id):
while True:
yield lobby.refresh()
gevent.sleep(1)
我尝试在函数中捕获异常,并在我用来包装@route 的装饰器中捕获异常,但两者都不起作用。我尝试制作一个 @error(500) 装饰器,但这也没有触发。这似乎与瓶子的内部结构有关。
编辑:我现在知道我需要捕获 socket.error,但我不知道我的代码中的下落