title: Failure to end Flask application
body: <p>I have a flask application as follows:</p>
  
  <pre><code>socketio2.run(app2, host="0.0.0.0", port=4998)
  </code></pre>
  
  <p>I created a method to end it as follows:</p>
  
  <pre><code>def shutdown_server():
      func = request.environ.get('werkzeug.server.shutdown')
      if func is None:
          raise RuntimeError('Not running with the Werkzeug Server')
      func()
  
  @app2.route('/shutdown', methods=['POST'])
  def shutdown():
      shutdown_server()
      print " shutdown"
      return 'Server shutting down...'
  </code></pre>
  
  <p>I get the following error</p>
  
  <blockquote>
    <p>Internal Server Error</p>
    
    <p>The server encountered an internal error and was unable to complete
    your request. Either the server is overloaded or there is an error in
    the application.</p>
  </blockquote>
  
  <p>My target is to end this Flask app and run a Python script afterwards. Any suggestions ?</p>