Hi I want to integrate schedule with my Flask app since I would need to do some routinely tasks. I found it here that he used threading to run it on the background. However when I tried it on mine, I cannot exit my app using Ctrl-C, I am using Windows. I will soon deploy it on Heroku, what's wrong?
Also is there any better and 'human-friendly' like schedule to do some routine task for Flask? Thanks.
Here is my code:
from flask import Flask
from datetime import datetime
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import mysql.connector
from mysql.connector import Error
import schedule
import time
from threading import Thread
app = Flask(__name__)
def job():
print("I'm working...")
def run_schedule():
while True:
schedule.run_pending()
time.sleep(1)
@app.route('/')
def homepage():
return '<h1>Hello World!</h1>'
if __name__ == '__main__':
schedule.every(5).seconds.do(job)
sched_thread = Thread(target=run_schedule)
sched_thread.start()
app.run(debug=True, use_reloader=False)