How do you run a script in flask without making the front end unresponsive?

I ran a shell script in flask, and the problem now is that this shell script takes a long time and causes the front-end web to become unresponsive during the run, so we have to wait until the script is finished. Is there any way to solve it? I"ve tried that using ajax, doesn"t work, because calling ajax"s url to execute the script still causes the page to get stuck. I have also tried to open multithreaded app.run (thread=true), which can be solved, but I need to open a new web page. I would like to ask if there is a better way. In addition, this script only runs in the background, and the relevant echo does not need to be rendered to the front end.

Mar.28,2021

any problem encountered in software engineering can be solved by adding an intermediate layer

you can use the method described in @ xdd1874 . You can use nohup, anyway, as long as it starts your shell.


you can leave the execution of the shell script to celery.

http://flask.pocoo.org/docs/1.


flask view calls subprocess.Popen to execute the script, and subprocess generates a child process to execute the script, which can be returned immediately

Menu