2

I'm building a web site using flask and I wish to do a Push to the client. I've followed real-time-events-python and I was able to create the website.

One thing that I've noticed is that when accessing the Javascript console, there is a GET every 500ms, so I'm wondering if the EventSource of javascript actually sends a GET to the server periodically to see if there are any updates, causing it to be a Busy Wait.

For information, I'm using Flask (python framework) for developing the website and chrome to access it.

Server Sent Events specification

2
  • No, events are asynchronous - no busy waiting. Polling might be a different thing.
    – Bergi
    Feb 20, 2013 at 19:40
  • thanks, i had a bug in the code that were causing this GETs requests.
    – barroca
    Feb 20, 2013 at 20:11

1 Answer 1

3

According to the link you provided, yes, the browser sends GETs as an implementation for server-sent events:

The actual protocol for Server-Sent Events is very simple. The client will open a standard connection to the server and make a GET request. It expects the server to hold open the socket and send new events by prefixing them with data: and terminating with two newline characters.

So, on the server side, the connection is supposed to remain open, while data is still being streamed through it. Keep in mind that Server-Sent Events allows for automatic reconnection, so if you are experiencing a lot of reconnects (which I imagine is what all those gets are, unless your client-side code is not written correctly), you should check to make sure that your server side is not closing the connection, which causes the browser to reopen the connection.

As for the "busy wait", if I'm understanding you correctly, you don't need to worry about this. This is handled by the browser, so your code doesn't block while waiting for something.

1
  • Only the first time the client sends the GET to the server. The problem was on the code that were causing the stream of GETs. Thanks for the answer.
    – barroca
    Feb 20, 2013 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.