簡體   English   中英

在python上安排任務

[英]Scheduling a task on python

我想運行一個每4小時運行一次函數的程序。 這種方式消耗最少的方法是什么?

我能想到的最簡單的方式(在python中,因為帖子用python標記):

import time

while True:
  do_task()
  time.sleep(4 * 60 * 60) # 4 hours * 60 minutes * 60 seconds

你可以使用sched模塊

這是文檔

https://docs.python.org/3.4/library/sched.html

使用內置計時器線程:

from threading import Timer

def function_to_be_scheduled():
   """Your CODE HERE"""

interval = 4 * 60 * 60   #interval (4hours)

Timer(interval, function_to_be_scheduled).start() 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM