Skip to content
Advertisement

Can I handle POST requests to Flask server in background thread?

I know how to receive data from POST request in main thread:

JavaScript

But can I do that in background thread to avoid blocking UI (rendering index.html)?

Advertisement

Answer

I’m assuming you want the html rendering and processing of your request to run concurrently. So, you can try threading in Python https://realpython.com/intro-to-python-threading/.

Let say you have a function that performs some processing on the request value, You can try this:

JavaScript

Thread will allow process_value to run in the background

Advertisement