How to implement a process to run every 5 minutes inside a flask server to check everything is okay?

Issue

I have a web interface built by flask which needs to flush one of its dictionaries every 5 minutes. How can I code this feature in? I have looked up threading, multiprocessing and Asyncio almost all examples are about complicated stuff and none of them is relevant to my very simple basic need.

Solution

Advanced Python Scheduler can do this for you and it is easy to use. It runs within the application and runs jobs that you schedule at intervals.

job = scheduler.add_job(myfunc, 'interval', minutes=5)

The documentations are clear and easy to setup. Also you can find Flask-APScheduler which is almost the same with few flask features.

Answered By – Elie Saad

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published