亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

在瀏覽器中保持 Flask 在沒有網頁的情況下運行

在瀏覽器中保持 Flask 在沒有網頁的情況下運行

米琪卡哇伊 2022-10-08 15:13:34
我有一個處理傳感器數據的本地燒瓶服務器。當溫度大于某個閾值時,它會獲取溫度值并調整燈光。到目前為止,它僅在一個客戶端保持瀏覽器打開該頁面時才有效。如果服務器可以在不一直打開瀏覽器的情況下更新溫度值并調整光線,那就太好了。如何讓它在后臺運行?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 [email protected]('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 [email protected]('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貢獻1824條經驗 獲得超8個贊

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



查看完整回答
反對 回復 2022-10-08
  • 1 回答
  • 0 關注
  • 101 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號