0

due_date であることを確認したときに起動するには、ファイルを追加するにはどうすればよいですか? 私はGoogleからいくつかの異なる方法を試しましたが、まだそれを理解するのに苦労しています. 現在、.py ファイルを起動してから 36 時間待機するように設定されています。

どんな助けも素晴らしいだろうし、それはこのサルを私の背中から永久に取り除くだろう!

import datetime
import croniter
import crontab
import time

c = croniter.croniter("0 9,10,11 * * TUE")
next_due_date = c.get_next(datetime.datetime)


while True:
now = datetime.datetime.now()
    if now > next_due_date:
        do_something(line.py)
        time.sleep(60 * 60 * 36)
    else:
        time.sleep(60 * 60 * 2)
4

1 に答える 1

1

.exe の場合は、python を起動した後に os.system("myexecutable.exe") を使用できます

import datetime
import croniter
import crontab
import time

c = croniter.croniter("0 9,10,11 * * TUE")
next_due_date = c.get_next(datetime.datetime)


while True:
    now = datetime.datetime.now()
    if now > next_due_date:
        do_something(line.py) # Edit: fixed tabbing; just in case it wasn't tabbed in 
                              #       your script
        # Use os.system to run the exe 
        os.system("myexecutable.exe")
        time.sleep(60 * 60 * 36)
    else:
        time.sleep(60) # Edit: I always find that it's better to have a smaller 
                       #       sleep time

subprocess モジュールを使用して、スクリプトを停止したり、代わりに exe がまだ実行されているかどうかを追跡したりすることもできます。

于 2013-07-30T16:32:42.700 に答える