【发布时间】:2014-01-14 18:44:12
【问题描述】:
我是 (python, stackoverflow, tornado) 的新手,所以请耐心等待 :)。纠正我。
我正在使用 Tornado 开发一个实时应用程序。当我在 Websocket 处理程序类中调用 self.close() 时,on_close 方法没有启动,这次我做了一个小包装,修复了问题并(例如)丢弃了连接的代理(纯 avascript wss api 客户端)正确。
所有网络问题都被丢弃了,因为我可怜的包装器运行良好并且我在 LAN 环境中。
有人有同样的问题吗?没有解释我睡不着。
谢谢你,真的。
## imports and other stuff
AGENTS = set()
class BackofficeWSSRailMain(tornado.websocket.WebSocketHandler):
def on_open(self):
pass
def on_message(self,raw_message):
json_msg=json.loads(raw_message)
login = function_that_process_login(json_msg)
if login == True:
AGENTS.add(self)
self.write_message("ok")
else:
self.write_message("nologin")
self.close() ### this part should fireup
### the on_close method but nothing
### happens so AGENT is not discarded.
### here is when i actually call on_close_wrapper(),
### the method below.
def on_close_wrapper(self):
self.close() ### this is my actual solution ,
### waiting for more research.
self.on_close()
def on_close(self):
AGENTS.discard(self)
## Calling ioloop ...
【问题讨论】:
标签: python web websocket tornado