old_contents: import tornado
  import tornadis
  
  
  @tornado.gen.coroutine
  def pubsub():
      client = tornadis.Client()
      yield client.connect()
      yield client.pubsub_psubscribe("foo*")
      yield client.pubsub_subscribe("bar")
      while True:
          reply = yield client.pubsub_pop_message()
          print(reply)
          if reply[3] == "STOP":
              yield client.pubsub_punsubscribe("foo*")
              yield client.pubsub_unsubscribe("bar")
              break
      yield client.disconnect()
  
  
  def stop_loop(future=None):
      excep = future.exception()
      if excep is not None:
          raise(excep)
      loop = tornado.ioloop.IOLoop.instance()
      loop.stop()
  
  
  loop = tornado.ioloop.IOLoop.instance()
  future = pubsub()
  loop.add_future(future, stop_loop)
  loop.start()
  
new_contents: import tornado
  import tornadis
  
  
  @tornado.gen.coroutine
  def pubsub_coroutine():
      # Let's get a connected client
      client = tornadis.PubSubClient()
      yield client.connect()
  
      # Let's "psubscribe" to a pattern
      yield client.pubsub_psubscribe("foo*")
  
      # Let's "subscribe" to a channel
      yield client.pubsub_subscribe("bar")
  
      # Looping over received messages
      while True:
          # Let's "block" until a message is available
          msg = yield client.pubsub_pop_message()
          print(msg)
          # >>> ['pmessage', 'foo*', 'foo', 'bar']
          # (for a "publish foo bar" command from another connection)
          if msg[3] == "STOP":
              # it's a STOP message, let's unsubscribe and quit the loop
              yield client.pubsub_punsubscribe("foo*")
              yield client.pubsub_unsubscribe("bar")
              break
  
      # Let's disconnect
      yield client.disconnect()
  
  
  def stop_loop(future=None):
      excep = future.exception()
      if excep is not None:
          raise(excep)
      loop.stop()
  
  
  loop = tornado.ioloop.IOLoop.instance()
  loop.add_future(pubsub_coroutine(), stop_loop)
  loop.start()
  
subject: update example