蟒蛇的瓶子长时间轮询? [英] Python's Bottle & Long-Polling?

查看:134
本文介绍了蟒蛇的瓶子长时间轮询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在localhost:8080上有一个一页的Bottle项目.

I currently have a one-page Bottle project working through localhost:8080.

出于这个问题的目的,假设没有页面,而是基本的短轮询聊天,从Python检索仅包含发件人姓名和消息正文的聊天行对象.

For the purposes of this question, assume that single page is naught but a basic short-polling chat, retrieving chatline objects from Python that contain only the sender's name and the body of the message.

这些聊天行对象存储在聊天对象中,并且该项目允许多个聊天.

Those chatline objects are stored in chat objects, with the project allowing multiple chats.

聊天和发件人由URL决定.例如,如果聊天行是从localhost:8080/chat/23/50发送的,则将其作为发送者50发送到聊天23,而localhost:8080/chat/23/*将在基本overflow:auto div中显示聊天23的所有聊天行.

The chat and sender is determined by the URL. For example, if a chatline is sent from localhost:8080/chat/23/50, it is sent to chat 23 as sender 50, and localhost:8080/chat/23/* will display all chatlines of chat 23 in a basic overflow:auto div.

当前的短轮询AJAX每秒从Python请求一次数据.我想使事情变得更实时,并决定采用长轮询(尽管如果您喜欢HTML5 WebSockets,我也不会介意对其进行学习).

The current short-polling AJAX requests data from Python once every second. I want to make things more real-time and have decided to go with long-polling (although if you love HTML5 WebSockets, I wouldn't mind learning about them too).

我的问题分为两个部分:

My question is in two parts:

  1. 我将如何在这样的聊天系统中实现长轮询方法,最好还是在仍使用Python的Bottle模块的情况下?
  2. 然后我如何通过可从外部访问的实际服务器(即,不仅可以从本地主机访问)交付项目?甚至通过LAN都可以使用它.

我知道长轮询会导致诸如Apache之类的服务器出现严重的性能问题,如果可以将这一事实纳入任何答案,我们将不胜感激.我想要一个尽可能可扩展的解决方案.

I'm aware that long-polling can cause severe performance issues with servers such as Apache and would appreciate it if that fact could be factored into any answers; I'd like as scalable a solution as possible.

感谢您的帮助!

推荐答案

我没有尝试过,但我认为您可以将瓶子与Tornado一起使用 http://www.tornadoweb.org/(请参见 Tornado-瓶装应用).

I didn't try myself but I think you can use bottle together works with Tornado http://www.tornadoweb.org/ (see Tornado - mount Bottle app).

可以用龙卷风进行长轮询.看看tornadio项目 https://github.com/mrjoes/tornadio .

It is possible to make long-polling with Tornado. Look at the tornadio project https://github.com/mrjoes/tornadio.

您可能还对 http://pypi.python.org/pypi感兴趣/bottle-tornado-websocket .我从没用过,但是看起来像您要找的东西.

You may also be interested in http://pypi.python.org/pypi/bottle-tornado-websocket. I never used this one but it looks like the thing you are looking for.

Tornado文档中有一个有关在生产环境中运行的部分: http ://www.tornadoweb.org/documentation/overview.html#running-tornado-in-production

Tornado doc has a section about running in production : http://www.tornadoweb.org/documentation/overview.html#running-tornado-in-production

我希望对您有帮助

这篇关于蟒蛇的瓶子长时间轮询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆