gpt4 book ai didi

Python 守护进程,每 x 秒重复一次函数

转载 作者:太空宇宙 更新时间:2023-11-04 09:06:44 24 4
gpt4 key购买 nike

<分区>

当代码在 Python 2.6 for Linux 中像守护进程一样工作时,我想每隔 x 秒重复一个函数。我有一些代码,但它给我带来了很多问题。是否可以调用另一个file.py而不是在里面写代码?

代码如下:

import daemon   
import threading

def hello():
print "hello, world"
t = threading.Timer(2.0, hello).start()

def run():
with daemon.DaemonContext():
hello()

if __name__ == "__main__":
run()

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com