Parallel Processing in Flask

Asked 2 years ago, Updated 2 years ago, 100 views

In flash

@app.route('/url1/')
def func1():

-----

@app.route('/url2/')
def func2():

If url1 and url2 receive requests almost simultaneously, how do I process them in parallel?

python flask

2022-09-29 21:27

1 Answers

If you are running it on a built-in server in Flask, you may be able to do the following:

 if__name__=="_main__":
    app.run(host='localhost', port=5555, threaded=True)

If running on uWSGI, setting "processes" to 2 or more in the uWSGI configuration file (uwsi.ini) will result in parallel processing in multiple processes.

 [uwsi]
processes = 2


2022-09-29 21:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.