AttributeError: 'Application' object has no attribute 'webSocketsPool'
AttributeError: 'Application' object has no attribute 'webSocketsPool'
我想在我的代码中使用 self.webSocketsPool = [],因为我有错误 AttributeError: 'Application' object has no attribute 'webSocketsPool'。
但我不知道我需要将其粘贴到我的龙卷风应用程序中的什么地方。
def make_app():
return tornado.web.Application([
(r"/", MainHandler),
(r"/dishtypes/(.*)", DishTypesHandler),
(r"/test", testhandler),
(r"/user/([0-9]+)", UserProfile),
(r"/login", LoginHandler),
(r"/testcookie", testcoockie),
(r"/registration", registrationHandler),
(r"/authentication", authHandler),
(r"/remc", removecockie),
(r"/adddish", addDish),
(r"/getusrbasket", getUserBasket),
(r"/payorder", payOrder),
(r"/clientorders", clientOrdersHandler),
(r"/clientorders/([0-9]+)", clientOrdersIdHandler),
(r'/websocket/?', WebSocket),
], **settings,
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
default_handler_class=NotFoundHandler)
if __name__ == "__main__":
app = make_app()
app.listen(8888)
tornado.ioloop.IOLoop.current().start()
错误行在此 class
class WebSocket(tornado.websocket.WebSocketHandler):
def open(self):
self.application.webSocketsPool.append(self)
def on_message(self, message):
db = self.application.db
message_dict = json.loads(message);
db.chat.insert(message_dict)
for key, value in enumerate(self.application.webSocketsPool):
if value != self:
value.ws_connection.write_message(message)
def on_close(self, message=None):
for key, value in enumerate(self.application.webSocketsPool):
if value == self:
del self.application.webSocketsPool[key]
您可以在创建后将列表附加到应用程序对象:
if __name__ == "__main__":
app = make_app()
app.webSocketsPool = []
app.listen(8888)
tornado.ioloop.IOLoop.current().start()
但是,出于性能原因,您应该考虑使用 set
而不是 list
。
我想在我的代码中使用 self.webSocketsPool = [],因为我有错误 AttributeError: 'Application' object has no attribute 'webSocketsPool'。 但我不知道我需要将其粘贴到我的龙卷风应用程序中的什么地方。
def make_app():
return tornado.web.Application([
(r"/", MainHandler),
(r"/dishtypes/(.*)", DishTypesHandler),
(r"/test", testhandler),
(r"/user/([0-9]+)", UserProfile),
(r"/login", LoginHandler),
(r"/testcookie", testcoockie),
(r"/registration", registrationHandler),
(r"/authentication", authHandler),
(r"/remc", removecockie),
(r"/adddish", addDish),
(r"/getusrbasket", getUserBasket),
(r"/payorder", payOrder),
(r"/clientorders", clientOrdersHandler),
(r"/clientorders/([0-9]+)", clientOrdersIdHandler),
(r'/websocket/?', WebSocket),
], **settings,
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
default_handler_class=NotFoundHandler)
if __name__ == "__main__":
app = make_app()
app.listen(8888)
tornado.ioloop.IOLoop.current().start()
错误行在此 class
class WebSocket(tornado.websocket.WebSocketHandler):
def open(self):
self.application.webSocketsPool.append(self)
def on_message(self, message):
db = self.application.db
message_dict = json.loads(message);
db.chat.insert(message_dict)
for key, value in enumerate(self.application.webSocketsPool):
if value != self:
value.ws_connection.write_message(message)
def on_close(self, message=None):
for key, value in enumerate(self.application.webSocketsPool):
if value == self:
del self.application.webSocketsPool[key]
您可以在创建后将列表附加到应用程序对象:
if __name__ == "__main__":
app = make_app()
app.webSocketsPool = []
app.listen(8888)
tornado.ioloop.IOLoop.current().start()
但是,出于性能原因,您应该考虑使用 set
而不是 list
。