为什么Flask调试器导致线程两次运行后台线程

时间:2019-04-22 01:40:32

标签: python multithreading flask

我在计划构建的非常原始的Rest服务器中有一个后台线程。唯一的问题是该后台线程似乎运行了两次,最小的可重复代码在这里:

MoviesViewModel @Inject constructor(private val movieService: MovieService): ViewModel()

import threading import time from flask import Flask app = Flask(__name__, template_folder='templates') def feedworker(): print("STARTING FEEDWORKER") while True: # background thread. never stop updating time.sleep(75) def runbackground(): feeder_thread = threading.Thread(target=feedworker) feeder_thread.daemon = True feeder_thread.start() if __name__ == "__main__": runbackground() app.run(debug=True) 应该启动挂起的后台runbackground。最大的问题是,它似乎两次启动了(终端输出):

feedworker

所有日志(还有更多日志)表明STARTING FEEDWORKER * Serving Flask app "testthread" (lazy loading) * Environment: production WARNING: Do not use the development server in a production environment. Use a production WSGI server instead. * Debug mode: on * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) * Restarting with stat STARTING FEEDWORKER * Debugger is active! * Debugger PIN: 297-719-925 已启动两次。但是如果您注释掉最后一行(feedworker)或仅注释app.run(debug=True),它将仅运行一次。

为什么调试器会使其运行两次?

0 个答案:

没有答案