0

How Would i Go About Adding a File To launch when it see that's it's the due_date? I've try'd quite i few different method's from Google but i'm still having a hard time figuring it out. currently it's set to wait 36 hours after launching the .py file.

any help would be great and it'd get this monkey off my back for good!

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 回答