Python 2.7 如何让Python每半小时做一件事?

Python 2.7 如何让Python每半小时做一件事?,python-2.7,Python 2.7,我希望我的代码(Python)每半小时执行一次。我正在使用Windows。例如,我希望它在11、11:30、12、12:30等时间运行 谢谢这应该调用函数一次,然后等待1800秒(半小时),调用函数,等待,等等 from time import sleep from threading import Thread def func(): your actual code code here if __name__ == '__main__': Thread(target

我希望我的代码(Python)每半小时执行一次。我正在使用Windows。例如,我希望它在11、11:30、12、12:30等时间运行


谢谢

这应该调用函数一次,然后等待1800秒(半小时),调用函数,等待,等等

from time import sleep
from threading import Thread


def func():
    your actual code code here


if __name__ == '__main__':

    Thread(target = func).start()
    while True:
        sleep(1800)
        Thread(target = func).start()


您还可以在命令提示符中使用该命令,这类似于linux中的cron。

Uh,假设脚本的两个副本同时运行(或者脚本的运行时间远小于30分钟),则“没有中断”,要想解决脚本运行时间超过预期间隔的问题,请使用Linux
at
atq
atrm
命令。使用
at
计划要运行的作业,并在脚本结束时使用
at
重新计划该作业。@marekful我没有Linux。我有窗户。谢谢你。