特定の時間にスクリプトを実行するスケジューラを作成しようとしています。
以下のコードは私自身のバージョンですが、時間が 23:59:59 になり、00:00:01 に達すると、何らかの理由でアイドリングが継続しないという問題があります...代わりに、callscripts を呼び出します() 一度アイドリングに戻ってしまう…
from datetime import date, timedelta
from sched import scheduler
from time import time, sleep, strftime
import random
s = scheduler(time, sleep)
random.seed()
def periodically(runtime, intsmall, intlarge, function):
## Get current time
currenttime = strftime('%H:%M:%S')
## If currenttime is anywhere between 23:40 and 23:50 then...
if currenttime > '23:40:00' and currenttime < '23:50:00':
## Call clear
clear()
## Update time
currenttime = strftime('%H:%M:%S')
## Idle time
while currenttime > '23:40:00' and currenttime < '23:59:59' or currenttime > '00:00:00' and currenttime < '01:30:00':
## Update time
currenttime = strftime('%H:%M:%S')
runtime += random.randrange(intsmall, intlarge)
s.enter(runtime, 1, function, ())
s.run()
def callscripts():
print "Calling Functions"
main1()
main2()
def main1():
print "Main1"
def main2():
print "Main2"
def clear():
print "Clearing"
while True:
periodically(2, -1, +1, callscripts)
これを修正する方法を知っている人、またはこれを行うためのより良い方法を知っている人はいますか?
どうもありがとうAEA