def listen(self):
pubsub = redis_conn.pubsub()<EOL>name = self.name<EOL>if isinstance(name, six.text_type):<EOL><INDENT>name = name.encode("<STR_LIT:utf-8>")<EOL><DEDENT>try:<EOL><INDENT>pubsub.subscribe([name])<EOL><DEDENT>except ConnectionError:<EOL><INDENT>app.logger.exception("<STR_LIT>")<EOL><DEDENT>log("<STR_LIT>".format(self.name))<EOL>for message in pubsub.listen():<EOL><INDENT>data = message.get("<STR_LIT:data>")<EOL>if message["<STR_LIT:type>"] == "<STR_LIT:message>" and data != "<STR_LIT:None>":<EOL><INDENT>channel = message["<STR_LIT>"]<EOL>payload = "<STR_LIT>".format(channel.decode("<STR_LIT:utf-8>"), data.decode("<STR_LIT:utf-8>"))<EOL>for client in self.clients:<EOL><INDENT>gevent.spawn(client.send, payload)<EOL><DEDENT><DEDENT>gevent.sleep(<NUM_LIT>)<EOL><DEDENT>
Relay messages from a redis pubsub to all subscribed clients.

        This is run continuously in a separate greenlet.