librelist archives

« back to archive

long polling with gevent and flask

long polling with gevent and flask

From:
Bolang
Date:
2012-03-09 @ 23:26
Hi all,
i just found this code https://bitbucket.org/danjac/chatbox/
Can someone experienced give a comment about this code?
Is this the right method to do long polling?

Thanks

long polling with gevent and flask

From:
Bolang
Date:
2012-03-09 @ 23:27
Hi all,
i just found this code https://bitbucket.org/danjac/chatbox/
Titled : Experimental long-polling with gevent and Flask

Can someone experienced give a comment about this code?
Is this the right method to do long polling?

Thanks

Re: [flask] long polling with gevent and flask

From:
Simon Sapin
Date:
2012-03-12 @ 08:09
Le 10/03/2012 00:27, Bolang a écrit :
> Hi all,
> i just found this codehttps://bitbucket.org/danjac/chatbox/
> Titled : Experimental long-polling with gevent and Flask
>
> Can someone experienced give a comment about this code?
> Is this the right method to do long polling?

Hi,

There is nothing special with long polling (compared eg. to websockets.) 
Just block when handling a request, and send the response later.

In thread-based servers, each thread handles at most one request at a 
time. So if your long-polling app has many users, you will need many 
threads very quickly.

Gevent on the other hand gives the illusion of blocking, but the 
"blocked" thread actually goes on to handle other requests in the 
meantime. The code you write really is the same, it just scales better.

If you want to use this in production have a look at gunicorn:
http://gunicorn.org/

The WSGI server in gevent looks almost like demo of what you could do 
with gevent, while gunicorn is first and foremost a WSGI server that can 
use gevent. (You’ll also get stuff like process management, ...)

Just keep in mind that the linked "chatbox" example uses an in-memory 
list to store messages. That won’t work if you have multiple processes, 
you’d need some other storage backend instead.

Regards,
-- 
Simon Sapin

Re: [flask] long polling with gevent and flask

From:
Ron DuPlain
Date:
2012-03-10 @ 00:18
Hi Bolang,

On Fri, Mar 9, 2012 at 3:26 PM, Bolang <boo.l4ng@gmail.com> wrote:
> Hi all,
> i just found this code https://bitbucket.org/danjac/chatbox/
> Can someone experienced give a comment about this code?
> Is this the right method to do long polling?
>
> Thanks

Here's the latest recommendation regarding long-polling and Flask:

http://flask.pocoo.org/mailinglist/archive/2011/12/5/long-polling-with-flask-on-heroku/#ad11f8dd03b7db65b8cebbb2d70d13b3

Below is the text of that message.

-Ron


On 12/5/11 11:34 AM, Colin L Rice wrote:
> I was trying to write a long polling application and need to push a byte
> down a http connection every 30 seconds or so. I was wondering if anyone
> has done something similar or if there is a easy way to do it within flask?
Hosted solutions like beaconpush.com or pusher.com exist.  If you want
to host this yourself there is juggernaut:
http://flask.pocoo.org/snippets/80/

IMO all of the solutions above beat any kind of hackery you can do yourself.


Regards,
Armin

Re: [flask] long polling with gevent and flask

From:
Bolang
Date:
2012-03-10 @ 00:46
On 03/10/2012 07:18 AM, Ron DuPlain wrote:
> Hi Bolang,
>
> On Fri, Mar 9, 2012 at 3:26 PM, Bolang<boo.l4ng@gmail.com>  wrote:
>> Hi all,
>> i just found this code https://bitbucket.org/danjac/chatbox/
>> Can someone experienced give a comment about this code?
>> Is this the right method to do long polling?
>>
>> Thanks
>
> Here's the latest recommendation regarding long-polling and Flask:
> 
http://flask.pocoo.org/mailinglist/archive/2011/12/5/long-polling-with-flask-on-heroku/#ad11f8dd03b7db65b8cebbb2d70d13b3

Hi Ron,
Thanks for the quick answer.
I have read that thread before asking my question.
I'm still asking because danjac's chatbox was not discussed in that thread.

Thanks

>
> Below is the text of that message.
>
> -Ron
>
>
> On 12/5/11 11:34 AM, Colin L Rice wrote:
>> I was trying to write a long polling application and need to push a byte
>> down a http connection every 30 seconds or so. I was wondering if anyone
>> has done something similar or if there is a easy way to do it within flask?
> Hosted solutions like beaconpush.com or pusher.com exist.  If you want
> to host this yourself there is juggernaut:
> http://flask.pocoo.org/snippets/80/
>
> IMO all of the solutions above beat any kind of hackery you can do yourself.
>
>
> Regards,
> Armin
>

Re: [flask] long polling with gevent and flask

From:
Ron DuPlain
Date:
2012-03-10 @ 07:52
On Fri, Mar 9, 2012 at 4:46 PM, Bolang <boo.l4ng@gmail.com> wrote:
> On 03/10/2012 07:18 AM, Ron DuPlain wrote:
>> On Fri, Mar 9, 2012 at 3:26 PM, Bolang<boo.l4ng@gmail.com>  wrote:
>>> i just found this code https://bitbucket.org/danjac/chatbox/
>>> Can someone experienced give a comment about this code?
>>> Is this the right method to do long polling?
>>>
>>> Thanks
>>
>> Here's the latest recommendation regarding long-polling and Flask:
>> 
http://flask.pocoo.org/mailinglist/archive/2011/12/5/long-polling-with-flask-on-heroku/#ad11f8dd03b7db65b8cebbb2d70d13b3
>
> Hi Ron,
> Thanks for the quick answer.
> I have read that thread before asking my question.
> I'm still asking because danjac's chatbox was not discussed in that thread.

Looking at chatbox, it's just proofing gevent with Flask.  To your
question of whether this is a good approach to long-polling, gevent is
a rather useful library.  You can build distributed services with
gevent using ginkgo (previously gservice):

https://github.com/progrium/GinkgoTutorial
https://github.com/progrium/ginkgo

Today at PyCon, there was a talk on ginkgo by Jeff Lindsay using the
tutorial linked here.  Look for the video to be posted.  The talk does
well to split a problem up into very small pieces, which you can
imagine carving out some bit of your application to one of Armin's
suggestions or something based on gevent.

-Ron

Re: [flask] long polling with gevent and flask

From:
Ron DuPlain
Date:
2012-03-12 @ 18:06
On Fri, Mar 9, 2012 at 11:52 PM, Ron DuPlain <ron.duplain@gmail.com> wrote:
> On Fri, Mar 9, 2012 at 4:46 PM, Bolang <boo.l4ng@gmail.com> wrote:
>> On 03/10/2012 07:18 AM, Ron DuPlain wrote:
>>> On Fri, Mar 9, 2012 at 3:26 PM, Bolang<boo.l4ng@gmail.com>  wrote:
>>>> i just found this code https://bitbucket.org/danjac/chatbox/
>>>> Can someone experienced give a comment about this code?
>>>> Is this the right method to do long polling?
>>>>
>>>> Thanks
>>>
>>> Here's the latest recommendation regarding long-polling and Flask:
>>> 
http://flask.pocoo.org/mailinglist/archive/2011/12/5/long-polling-with-flask-on-heroku/#ad11f8dd03b7db65b8cebbb2d70d13b3
>>
>> Hi Ron,
>> Thanks for the quick answer.
>> I have read that thread before asking my question.
>> I'm still asking because danjac's chatbox was not discussed in that thread.
>
> Looking at chatbox, it's just proofing gevent with Flask.  To your
> question of whether this is a good approach to long-polling, gevent is
> a rather useful library.  You can build distributed services with
> gevent using ginkgo (previously gservice):
>
> https://github.com/progrium/GinkgoTutorial
> https://github.com/progrium/ginkgo
>
> Today at PyCon, there was a talk on ginkgo by Jeff Lindsay using the
> tutorial linked here.  Look for the video to be posted.  The talk does
> well to split a problem up into very small pieces, which you can
> imagine carving out some bit of your application to one of Armin's
> suggestions or something based on gevent.

Here's the video:

"In this talk we learn how to throw together a distributed system
using gevent and a simple framework called gservice. We'll go from
nothing to a distributed messaging system ready for production
deployment based on experiences building scalable, distributed systems
at Twilio."

http://pyvideo.org/video/637/throwing-together-distributed-services-with-geven

-Ron

Re: [flask] long polling with gevent and flask

From:
Tobias Bradtke
Date:
2012-03-12 @ 22:53
Am 12.03.2012 19:06, schrieb Ron DuPlain:
> Here's the video:
>
> "In this talk we learn how to throw together a distributed system
> using gevent and a simple framework called gservice. We'll go from
> nothing to a distributed messaging system ready for production
> deployment based on experiences building scalable, distributed systems
> at Twilio."
>
> http://pyvideo.org/video/637/throwing-together-distributed-services-with-geven
>
> -Ron
Right link seems to be 
http://pyvideo.org/video/642/throwing-together-distributed-services-with-geven
But thanks for sharing!

webwurst