[FIXED] Python Flask application stuck with no response


I have a Flask application running on a linux server and noticed that occasionally it get stuck when sending POST request to it and then go to GET and try POST again (then it get stuck). It get ‘un-stuck’ if I do GET again (then last POST that was stuck gets completed).

First part of Flask app is:

@app.route('/myroute', methods=['GET','POST'])
def myfunction():
    if request.method == 'POST':

Starting it with:
FLASK_APP=myflask.py FLASK_DEBUG=1 python -m flask run --port 8300 --host= --no-reload.

Also did setup parallel threads with:

if __name__ == '__main__':

but that did not prevent for getting stuck.


The code inside if __name__ == '__main__' is not run when you start the application using python -m flask run ....

So the threaded=True-part is not in effect.

Use the --with-threads command-line switch.

$ flask run --help
Usage: flask run [OPTIONS]

  Runs a local development server for the Flask application.

  This local server is recommended for development purposes only but it can
  also be used for simple intranet deployments.  By default it will not
  support any sort of concurrency at all to simplify debugging.  This can be
  changed with the --with-threads option which will enable basic

  The reloader and debugger are by default enabled if the debug flag of
  Flask is enabled and disabled otherwise.

  -h, --host TEXT                 The interface to bind to.
  -p, --port INTEGER              The port to bind to.
  --reload / --no-reload          Enable or disable the reloader.  By default
                                  the reloader is active if debug is enabled.
  --debugger / --no-debugger      Enable or disable the debugger.  By default
                                  the debugger is active if debug is enabled.
  --eager-loading / --lazy-loader
                                  Enable or disable eager loading.  By default
                                  eager loading is enabled if the reloader is
  --with-threads / --without-threads
                                  Enable or disable multithreading.
  --help                          Show this message and exit.

Answered By – codeape

Answer Checked By – Gilberto Lyons (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published