Last active 10 months ago

這段程式碼使用 schedule 設定每 5 分鐘執行一次指定任務,並透過主迴圈不斷檢查和執行排程中的任務。

timmy revised this gist 10 months ago. Go to revision

No changes

timmy revised this gist 11 months ago. Go to revision

No changes

timmy revised this gist 11 months ago. Go to revision

1 file changed, 18 insertions

task_scheduler_example.py(file created)

@@ -0,0 +1,18 @@
1 + import time
2 + import schedule
3 +
4 + # 定義任務函數
5 + def job(param):
6 + print(f"執行任務,參數: {param}")
7 +
8 + if __name__ == "__main__":
9 + # 設定排程,每 5 分鐘執行一次
10 + schedule.every(5).minutes.do(job, param="範例參數")
11 +
12 + print("排程已啟動,每 5 分鐘執行一次任務。")
13 +
14 + while True:
15 + # 執行所有等待的任務
16 + schedule.run_pending()
17 + # 暫停 1 秒,避免高頻運算
18 + time.sleep(1)
Newer Older