2 回答
TA貢獻1834條經驗 獲得超8個贊
您的主要功能不會循環,因此只會執行一次。您需要添加一個循環,例如:
def main():
while 1 :
print('Init main task on background')
time.sleep(1)
TA貢獻2012條經驗 獲得超12個贊
線程中帶有“主”代碼的選項(我沒有包含您需要的所有導入 - 您的代碼顯然需要包含您已經擁有的代碼):
import threading
class MonitorThread(threading.Thread):
def run(self):
debug_log("Monitor system thread")
try:
while 1: # Monitor the system forever while powered
print('Init main task on background')
# ... Add here whatever you want to do forever
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
MonitorThread().start()
app = Flask(__name__) # Start webpage
# Flask web page code
@app.route("/")
def index():
# ... Include all of your Flask web page code generation
if __name__ == "__main__":
app.run(debug=False, host="0.0.0.0")
如果這不起作用,請告訴我,因為我的應用程序非常復雜,但會永遠運行并按要求提供網頁,所以這只是因為我遺漏了一些東西。
添加回答
舉報
