pogo
pogo

Reputation: 1550

Show progress using Ajax on a flask program

I created a web application to process large amounts of data using python flask framework. I created a form and I get the input parameters for the data consuming program when the user submits the form. The program takes about 20-30 mins to complete and I'd like to show the status of the program to the user in a webpage.

How do I achieve this?

After the user submits the data, do I need to run the program on a separate thread and redirect to a success page on a different thread? How do I communicate between the program and the POST page? How do I refresh the page at continuous intervals?

Thanks in advance.

Upvotes: 0

Views: 561

Answers (2)

laike9m
laike9m

Reputation: 19328

I happened to have done the same thing several months ago. The code is here. Basically you use Celery+rabbitmq to run your task in background. Hope it helps.

Upvotes: 1

Bobby Russell
Bobby Russell

Reputation: 475

For tasks that are too long-lived to exist entirely within the request/response cycle, task queues are a good option. Check out celery.

You can string together tasks to update your app's state when your task is finished, then poll your app with setInterval() and clearInterval() browser APIs.

Upvotes: 1

Related Questions