Opengist

Explore

  • All gists
  • Topics
  • Users
Give feedback on the new UI Powered by Opengist ⋅ 45ms

user:thomas gists created by user

title:mygist gists with given title

description:sync gists with given description

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

all:systemctl search all fields

Login
c

cron

Recently created Least recently created Recently updated Least recently updated

timmy / Python 排程任務管理

Last active 6 hours ago automation cron python schedule-library scheduling task-scheduler

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

0 0 0 1
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="範例參數")