title: python How can I run flask app in a thread?
body: <p>How can I run my flask app in a separate thread?
  I am able to run my flask app in main, but </p>
  
  <p>I need to launch the flask app from a thread, that thread should be running while in main thread I initiate an event for the thread engine to start.</p>
  
  <p>so this works fine</p>
  
  <pre><code>@app.route("/voice", methods=['GET', 'POST'])
  def voice():
    .........
    return str(resp)
  
  @app.route("/mainFlow", methods=['GET', 'POST'])
  def mainFlow():
      """Respond """
      .......
  
      return str(resp)
  
  
  if __name__ == "__main__":
      app.run(debug=True)
  </code></pre>
  
  <p>but I need something like this </p>
  
  <pre><code>def myIVR():
      print("-----------------Thrd1-myIVR --------------------")
      app = Flask(__name__)
      app.run(debug=True)
  
      @app.route("/voice", methods=['GET', 'POST'])
      def voice():
        ........
        return str(resp)
  
      @app.route("/mainFlow", methods=['GET', 'POST'])
      def mainFlow():
          """Respond to """
          resp = VoiceResponse()
  
  def myTest():
      print("E2Etest")
      thrd1 = threading.Thread(target=myIVR, args=[])
      thrd1.start()
      print("trigger event")
      #xyz()
  
  ################################################################
  def main():
      myTest()
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>I get this error</p>
  
  <pre><code>  File "C:\......\AppData\Local\Programs\Python\Python37-32\lib\signal.py", line 47, in signal
      handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
  ValueError: signal only works in main thread
  </code></pre>