On Tue, Aug 5, 2014 at 5:14 PM, Petru Ciobanu <[email protected]>
wrote:

>
> What is the correct way to handle connection closed by client? ...
> explanation is following.
>
>  To maintain opened a connection I use advices founded in
> streaming#streaming-with-generators
> <http://turbogears.readthedocs.org/en/latest/cookbook/streaming.html#streaming-with-generators>
>  page,
> with the only difference that I should interrupt while cycle only when the
> client has disconnected.
>

GeneratorExit exception is raised inside your generator, catch the
exception and do whatever cleanup you require.
See
http://runnable.com/U-D9lkz30Sk6Vg4m/server-side-events-with-turbogears2-for-python
for a practical example (Note that you must download it and run on your
local PC as on runnable the connection is never closed probably due to
runnable proxy)


> When the client is resetting the connection for example when refreshing
> the page... I get this error when trying to send an event to the client,
> after the connection was closed:
>
>   File "/virtenv/lib/python2.7/site-packages/gevent/socket.py", line 435,
> in send
>
>     return sock.send(data, flags)
> error: [Errno 32] Broken pipe
>
>
This is a known GEVENT issue, the Broken Pipe error can usually just be
ignored, but there is an open ticket on gevent to suppress the error
message: https://github.com/surfly/gevent/pull/377



> somewhere I found that in a wsgi environment I could use
>
> while True:
>     websocket = request.environ['wsgi.websocket']
>     if not websocket.socket:
>         break
>     else:
>         send_next_event()
> closed_connection_handler()
>
> but apparently, this is not a solution for Turbogears as there is not a
> wsgi.websocket key in request.environ dictionary. And I can't find a gevent
> environment variable suitable for this.
>

That is actually WebSocket related, SSE doesn't use web sockets so you
don't have the wsgi.websocket environment key :D

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.

Reply via email to