I have a server used Redis and Socket.IO. If a user connect to the socket.IO, server will run a greenlet and subscribe to redis channel. If the user disconnect, the greenlet will unsubscribe the channel.
After a lot of connection and disconnection, I use 'client list' command in redis-cli, I found that the number of unsubscribe is additive and it will never closed like other command. And it will finally cause 'Too Many Files Open Error'
My Code is
class ListenMsgThreading(Greenlet):
def __init__(self, app_eui, request_sid):
Greenlet.__init__(self)
self.ps = redis_db.pubsub()
self.ps.subscribe('channel')
def stop(self):
self.ps.unsubscribe('channel')
def run(self):
for item in self.ps.listen():
if item is not None:
print(item)
I notice that the reason may be
timeout only applies to number clients and it does not apply to Pub/Sub clients, since a Pub/Sub connection is a push style connection so a client that is idle is the norm.
Should I implement the timeout for unsubscribe command? Or use other method to stop subscribe?
redis_db
an actual StrictRedis() object? – Paul Becotte