第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在瀏覽器中保持 Flask 在沒有網(wǎng)頁的情況下運行

在瀏覽器中保持 Flask 在沒有網(wǎng)頁的情況下運行

米琪卡哇伊 2022-10-08 15:13:34
我有一個處理傳感器數(shù)據(jù)的本地?zé)糠?wù)器。當(dāng)溫度大于某個閾值時,它會獲取溫度值并調(diào)整燈光。到目前為止,它僅在一個客戶端保持瀏覽器打開該頁面時才有效。如果服務(wù)器可以在不一直打開瀏覽器的情況下更新溫度值并調(diào)整光線,那就太好了。如何讓它在后臺運行?temperture = 0threshold_temp = 0def read_temp():    #read temperature valuesserver = Flask(__name__)socketio = SocketIO(server)app = dash.Dash(__name__, server = server, url_base_pathname="/dash/")@server.route('/_stuff')def stuff():    global threshold_temp    temperature = read_temp()    if temperature >= threshold_temp:            #change light    else:            #do not change light    return jsonify(result = temperature)#Change Threshold@socketio.on('message')def handleMessage(msg):    global threshold_temp    threshold_temp = float(msg)    send(msg, broadcast=True)    f = open("Threshold.txt", "w")    f.write(msg)    f.close()#Adjust Threshold on Connection of Client@socketio.on('connect')def on_connect():    global threshold_temp    f = open("Threshold.txt", "r")    threshold_temp = float(f.read())    send(threshold_temp, broadcast=True)@server.route('/')def index():    return render_template('index.html')if __name__ == '__main__':    socketio.run(server, host='0.0.0.0', port=80, debug=False)
查看完整描述

1 回答

?
有只小跳蛙

TA貢獻(xiàn)1824條經(jīng)驗 獲得超8個贊

聽起來你想運行一個后臺任務(wù);消息代理是處理這類事情的好方法。python-rqcelery是很好的選擇。



查看完整回答
反對 回復(fù) 2022-10-08
  • 1 回答
  • 0 關(guān)注
  • 123 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號