How to implement a cherrypy server with long-polling enabled path?

31 views
Skip to first unread message

北美38fule

unread,
Dec 18, 2019, 2:59:45 PM12/18/19
to cherrypy-users
I am a newbie in cherrypy. I've done some research on google but didn't get much helpful information.
Could someone please point out if cherrypy allows me to write a simple server that has long-polling enabled path?
The scenario is like: whenever the database on backend has some updated information, it sends signals to the frontend to updates all relevant display accordingly.

Is this achievable using cherrypy? Or I will need tornado-like framework? Could someone also point out a newbie-friendly tutorial for this purpose? Thanks.

Tim Roberts

unread,
Dec 18, 2019, 11:54:33 PM12/18/19
to cherryp...@googlegroups.com
That’s just not how HTTP works. The right way to do this is “pull model”: have the clients (that is, the browsers) poll for the new data. It’s possible to use WebSockets to set up a persistent connection to a server, but you’d want another TCP server, not an HTTP server. HTTP is fire and forget. One request, one response, close the socket.

General TCP servers are basically trivial to write in Python.

Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Björn Pedersen

unread,
Dec 19, 2019, 3:06:18 AM12/19/19
to cherrypy-users
A quick google search for pytho socketio gives quite a few hits.

See https://python-socketio.readthedocs.io/en/latest/intro.html, this should be easys to integrate with  cherrypy as  well.
Pure websockets: ws4py has  cherrypy integration.

Björn

ingo janssen

unread,
Dec 19, 2019, 7:19:29 AM12/19/19
to cherryp...@googlegroups.com
What DB are you using. Can it send messages? You can build a plug in
that sits on the cherrypy bus and listens to messages and then pushes
them to a SSE publisher.

For example something like
https://gist.github.com/ingoogni/169a2b8b1e484c71c95c55a2da2a65f0 to
listen to postgreSQL and something like this to publish the messages:
https://gist.github.com/ingoogni/a7f7c0fed9e96b3545e9a8c6139d80b0
> --
> You received this message because you are subscribed to the Google
> Groups "cherrypy-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to cherrypy-user...@googlegroups.com
> <mailto:cherrypy-user...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/cherrypy-users/a2124195-11dc-46d2-baf2-7a9040bd9639%40googlegroups.com
> <https://groups.google.com/d/msgid/cherrypy-users/a2124195-11dc-46d2-baf2-7a9040bd9639%40googlegroups.com?utm_medium=email&utm_source=footer>.

北美38fule

unread,
Dec 19, 2019, 1:47:48 PM12/19/19
to cherrypy-users
SQLite, along with sqlalchemy in Python. I'm not aware of the feature you suggest, where can I find more information? Thank you!


On Thursday, December 19, 2019 at 4:19:29 AM UTC-8, ingo janssen wrote:
What DB are you using. Can it send messages? You can build a plug in
that sits on the cherrypy bus and listens to messages and then pushes
them to a SSE publisher.

For example something like
https://gist.github.com/ingoogni/169a2b8b1e484c71c95c55a2da2a65f0 to
listen to postgreSQL and something like this to publish the messages:
https://gist.github.com/ingoogni/a7f7c0fed9e96b3545e9a8c6139d80b0



On 18-12-2019 03:23, 北美38fule wrote:
> I am a newbie in cherrypy. I've done some research on google but didn't
> get much helpful information.
> Could someone please point out if cherrypy allows me to write a simple
> server that has long-polling enabled path?
> The scenario is like: whenever the database on backend has some updated
> information, it sends signals to the frontend to updates all relevant
> display accordingly.
>
> Is this achievable using cherrypy? Or I will need tornado-like
> framework? Could someone also point out a newbie-friendly tutorial for
> this purpose? Thanks.
>
> --
> You received this message because you are subscribed to the Google
> Groups "cherrypy-users" group.
> To unsubscribe from this group and stop receiving emails from it, send

北美38fule

unread,
Dec 19, 2019, 1:49:51 PM12/19/19
to cherrypy-users
Thanks for your suggestion. I've read some articles saying that websocket would be an overkill. My application doesn't require high frequency bi-directional communications. It's only occasionally needs some updates from backend. So I'm reluctant to adopt websocket in my use case.

On Wednesday, December 18, 2019 at 8:54:33 PM UTC-8, Tim Roberts wrote:

Tim Roberts

unread,
Dec 20, 2019, 3:46:01 AM12/20/19
to cherryp...@googlegroups.com
On Dec 19, 2019, at 10:49 AM, 北美38fule <38fule.nor...@gmail.com> wrote:
>
> Thanks for your suggestion. I've read some articles saying that websocket would be an overkill. My application doesn't require high frequency bi-directional communications. It's only occasionally needs some updates from backend. So I'm reluctant to adopt websocket in my use case.

Then isn’t it clear that having Javascript on your web site do an AJAX request to poll every few seconds is the right method? Nothing unusual or non-standard about that.
Reply all
Reply to author
Forward
0 new messages