How to start multithreading to monitor the database and execute scripts according to the status when Flask starts

there is a problem in the WEB project, which requires the background to refresh and monitor the data in the database in real time.
every time FLASK starts, it starts a thread to monitor the order placed by the customer and whether the order has been paid successfully.
after the customer changes the database state after the payment is successful, one more thread is opened to execute the script to ship the order.
how to implement it in Flask?


consider using ThreadPoolExecutor in concurrent.futures

from concurrent.futures import ThreadPoolExecutor
executor = ThreadPoolExecutor(2) -sharp
...
executor.submit(your_function)
Menu