在每个循环内,线程将打印两次。在这种情况下,每3秒打印两次。我希望它只打印一次。
在烧瓶上:
from flask import Flask
import threading
from time import sleep
app = Flask(__name__)
@app.route('/')
def index():
return 'ok'
def func():
count = 1
while True:
print(count)
count += 1
sleep(3)
t = threading.Thread(target=func)
t.setDaemon(True)
t.start()
if __name__ == '__main__':
app.run(debug=True)
输出:
1
1
2
2
3
3
...
预期输出:
1
2
3
...
我弄清楚了原因。
当以调试模式在Flask中运行诸如线程和apscheduler之类的模块时:on ...会发生。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句