Skip to content
Advertisement

How to let a Flask web page (route) run in the background while on another web page(route)

So i’m creating this application and a part of it is a web page where a trading algorithm is testing itself using live data. All that is working but the issue is if i leave (exit) the web page, it stops. I was wondering how i can keep it running in the background indefinitely as i want the algorithm to keep doing it’s thing.

This is the route which i would like to run in the background.

JavaScript

I’ve looked into multi-threading but not too sure if that’s the right thing for the job. I am kind of still new to flask so hence the poor question. If you need more info, please do comment.

Advertisement

Answer

You can do it the following way – this is 100% working example below. Note, in production use Celery for such tasks, or write another one daemon app (another process) by yourself and feed it with tasks from http server with the help of message queue (e.g. RabbitMQ) or with the help of common database.

If any questions regarding code below, feel free to ask, it was quite good exercise for me:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement