2 回答

TA貢獻(xiàn)1834條經(jīng)驗 獲得超8個贊
您的主要功能不會循環(huán),因此只會執(zhí)行一次。您需要添加一個循環(huán),例如:
def main():
while 1 :
print('Init main task on background')
time.sleep(1)

TA貢獻(xiàn)2012條經(jīng)驗 獲得超12個贊
線程中帶有“主”代碼的選項(我沒有包含您需要的所有導(dǎo)入 - 您的代碼顯然需要包含您已經(jīng)擁有的代碼):
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")
如果這不起作用,請告訴我,因為我的應(yīng)用程序非常復(fù)雜,但會永遠(yuǎn)運行并按要求提供網(wǎng)頁,所以這只是因為我遺漏了一些東西。
添加回答
舉報