定期运行应用程序

时间:2017-05-23 02:01:00

标签: python multithreading timer

以下程序正在运行。并非所有程序都显示在此处。此处仅显示相关部分。关键是我想定期运行应用程序以从网站抓取新数据。我使用了parallelthread但却失败了。

timer

以下是运行

后的错误消息
import time, threading  
# some parts of the program are not shown here for their irrelevancy.
app = Flask(__name__)

@app.route('/')
@app.route('/weather')
def weather() -> 'html':
    place = "논현동 air quality information"
    # bringing in the crawled data 
    (match_web, match_db, update) = run_crawl()
    air_pm = str(match_web[0])
    ozone = str(match_web[1])
    total_air = str(match_web[2])
    update_time = update

    return render_template('weather.html', place = place, air_pm = air_pm, ozone 
= ozone, total_air = total_air, update_time = update)

if __name__ == '__main__':
    threading.Timer(100, app.run(debug=True, host='0.0.0.0')).start()

1 个答案:

答案 0 :(得分:0)

Timer的第二个参数必须是一个函数。试试这个

threading.Timer(100, lambda: app.run(debug=False, host='0.0.0.0')).start()