from apscheduler.schedulers.background import BackgroundScheduler
from flask import Flask, g
app = Flask(__name__)
scheduler = BackgroundScheduler()
stopwords = []
a = 0
def load_stopwords():
global stopwords, a
a += 1
stopwords.append(a)
@app.before_first_request
def start_scheduler():
scheduler.add_job(load_stopwords, 'interval', seconds=3)
scheduler.start()
@app.before_request
def before_request():
g.stopwords = stopwords
@app.route('/')
def index():
return ', '.join(g.stopwords)
if __name__ == '__main__':
app.run()
# """
# import requests
# url = "http://127.0.0.1:5000/index"
# data = requests.get(url)
# print(data.text)
# """
python Flask中加入异步定时加载本地停用词
于 2023-08-21 10:43:39 首次发布