title: mqtt client does not receive message in case of thread and rest-api
body: <p>I have a python script, which based on flask and mqtt. The use case is to receive a request via rest-api then to create a new thread which publishes some messages on mosquitto mqtt and expects a response (see subscribe). My problem is that I don't receive any messages. I think it has something to do with the thread, because without the thread it's working very fine..
  Do you know what can be the problem?</p>
  
  <p>Thank you in anticipation!</p>
  
  <p>here the code:</p>
  
  <pre><code>from flask import Flask, Response
  import paho.mqtt.client as mqtt
  from threading import Thread
  import threading
  
  app = Flask(__name__)
  lock = threading.Lock()
  
  def on_connect(client, userdata, flags, rc):  # The callback for when the client connects to the broker
      print("Connected with result code {0}".format(str(rc)))  # Print result of connection attempt
      client.subscribe("/mytopic")
  
  
  def on_message(client, userdata, msg):  # The callback for when a PUBLISH message is received from the server.
      print(msg.topic)
  
  
  client = mqtt.Client(client_id=client_name, clean_session=True)
  client.on_connect = on_connect  # Define callback function for successful connection
  client.on_message = on_message  # Define callback function for receipt of a message
  client.username_pw_set(mqtt_user, mqtt_password)
  client.loop_start()
  client.connect(mqtt_host)    
  
  
  def test(param1, param2):
     lock.acquire()
     try:
  
        ret = client.publish("/mytopic", "")
        while True:
              check the response from mqtt =&gt; but i don't get the response anymore
              ....
              break
      finally:
          lock.release()
      return result
  
  
  @app.route('/test/check', methods=['POST'])
  def check():
      global sessionId
      sessionId = sessionId + 1
      t = Thread(target=test, args=(sessionId,None))
      t.start()
      return {'id': sessionId, 'eta': 0}
  
  
  if __name__ == '__main__':
      app.run(debug=True)
  </code></pre>