如何让 Python 每半小时做一些事情? [英] How to make Python do something every half an hour?

查看:94
本文介绍了如何让 Python 每半小时做一些事情?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like my code (Python) to execute every half an hour. I'm using Windows. For example, I would like it to run at 11, 11:30, 12, 12:30, etc.

谢谢

推荐答案

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

This should call the function once, then wait 1800 second(half an hour), call function, wait, ect.

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()

这篇关于如何让 Python 每半小时做一些事情?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆