title: How to stop Python Kafka Consumer in program?
body: <p>I am doing Python Kafka consumer (trying to use kafka.consumer.SimpleConsumer or kafka.consumer.simple.SimpleConsumer in <a href="http://kafka-python.readthedocs.org/en/latest/apidoc/kafka.consumer.html" rel="noreferrer">http://kafka-python.readthedocs.org/en/latest/apidoc/kafka.consumer.html</a>). When I run the following piece of code, it will run all the time, even if all messages consumed. <strong>I hope the consumer will stop if it consume all the messages. How to do it?</strong> Also I have no idea how to use stop() function (which is in base class kafka.consumer.base.Consumer).</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I used signal handler to call consumer.stop(). Some error messages were printed out to the screen. But the program still was stuck in the for-loop. When new messages came in, the consumer consumed them and printed them. I also tried client.close(). But the same result.</p>
  
  <p><strong>I need some ways to stop the for-loop gracefully.</strong></p>
  
  <pre><code>        client = KafkaClient("localhost:9092")
          consumer = SimpleConsumer(client, "test-group", "test")
  
          consumer.seek(0, 2)# (0,2) and (0,0)
  
          for message in consumer:
              print "Offset:", message.offset
              print "Value:", message.message.value
  </code></pre>
  
  <p>Any help is welcome. Thanks.</p>