chat icon indicating copy to clipboard operation
chat copied to clipboard

How to handle client closed event?

Open yishh opened this issue 11 years ago • 3 comments

It seems that the redis connection keeped when the page is closed. How to handle client closed event ?

yishh avatar Mar 13 '13 07:03 yishh

Hey Yishh, did you find a solution for the issue? I'm having the same problem!

barroca avatar Mar 14 '13 14:03 barroca

This should be possible using a closeable iterator: lift the generator in the __iter__ method of an object (can just convert event_stream to a class) and add a close method, which will be called on connection close.

However, this may only happen when a write to the socket fails, so there probably needs to be a "heartbeat" regularly sending something irrelevant (e.g. a line of comment) in order to trigger the failure, and thus the closing of the iterator.

As far as I can see, for the current redis-based implementation this would require a timeout on pubsub.listen(), which I don't believe exists.

Here's a zmq conversion demonstrating it: https://github.com/masklinn/chat/blob/zmq/app.py

masklinn avatar Jun 09 '13 17:06 masklinn