title: How to exit mqtt forever_loop?
body: <p>I created a program to receive data, recently.</p>
  
  <p>And I want to break the loop When I receive a specific data.</p>
  
  <p>For example, if I receive "1" to another machine, then my system will regard it
  as an illegal number, then it will break the loop to stop receiving data.</p>
  
  <p>Here is my code in the below, and you can also see <code>client.loop_stop()</code> in my code. But it not works.</p>
  
  <p>I have also tried <code>sys.exit()</code> in my code.</p>
  
  <p>Although it works in this case, it is not suitable to be utilized in other situation.</p>
  
  <p>So I am wondering about how to break the loop of the client, I don't want to close the whole system by  <code>sys.exit()</code>. </p>
  
  <pre><code>import paho.mqtt.client as mqtt
  # This is the Subscriber
  a=""
  def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))
    client.subscribe("hello")
  
  def on_message(client, userdata, msg):
      info=msg.payload.decode()
      print info
      if str(info)=='1':
        print "OK"
        client.loop_stop()
  
  
  client = mqtt.Client()
  client.connect("myIp",1883,60)
  
  client.on_connect = on_connect
  client.on_message = on_message
  client.loop_forever()
  </code></pre>