【Python】指定の時間にある関数を実行する

cron を使わずに、指定の時間に、ある関数を実行させてみる。

【1】.1秒毎のタイマーを繰り返す。
【2】.指定の時間にある関数を実行。

def timer():
timeStr = datetime.now().strftime("%H:%M:%S")
print(timeStr)
if timeStr == '19:00:00':
exe()
else:
next()
def next():
t = threading.Timer(1, timer)
t.start()
def exe():
print("exe")
next()

もし、1秒間隔の精度をあげたければ、

↓こちらのサイトのように、100ミリ秒単位で設定してもいい。

関連記事

返信を残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA