你能帮我完成并行任务吗?我这样做了几天,我还有更多想法。我想main()在后台连续运行任务以检查温度和控制输出。
当我启动 web 服务器时,函数main()只执行一个循环,并且 flaskapp()运行正常。
非常感谢。
from flask import Flask, render_template
import datetime
import time
from random import random
from random import seed
import threading
from pytz import utc
import atexit
app = Flask(__name__)
myThread = threading.Thread()
POOL_TIME = 5 #seconds
@app.route('/')
def index():
return render_template('index.html', **templateData)
@app.route("/<deviceName>/<action>")
def action(deviceName, action):
return render_template('index.html', **templateData)
def main():
print('Init main task on background')
time.sleep(1)
if __name__ == '__main__':
#myThread = threading.Timer(POOL_TIME, main, ())
#myThread.start()
threading.Thread(target = main()).start()
app.run(debug=True, host='0.0.0.0')
#app.run(threaded=True)
MMMHUHU
繁花如伊
相关分类