2

I have a flask built rest api served by waitress. I am limited to using one thread in my api (I have a model which is unstable if multi threading is allowed) this means that I wanted to look into implementing multi-processing to speed up request processing time. How can I do this? Also In doing this would I be creating a new instance of the api for each of my machine’s core? Really new to this area and unsure of how multi-processing would work within an api.

Ngillie
  • 21
  • 1
  • 2

1 Answers1

2

Just pass the function argument thread while using the serve function. Please see the below example, here 8 threads will be used.

app = Flask(__name__)
app.config['CORS_HEADERS'] = 'Content-Type'


@app.route("/")
def main():
    return "Welcome1"

if __name__ == "__main__":
   #app.run() ##Replaced with below code to run it using waitress 
   serve(app, host='0.0.0.0', port=8000,threads= 8)
Rohit Patil
  • 103
  • 1
  • 7