不同的守护进程实现

时间:2012-08-14 03:36:46

标签: python daemon background-process daemons

我是python的新手,到目前为止我只是略过了编程的表面,这就是为什么我对守护进程感到困惑。我一般都知道他们做了什么,但我不确定实现它们的最佳方法是在python中。我找到了this链接,演示了如何在python中创建守护进程。但是,我想知道是否这个

#!/usr/bin/env python3.2
import threading

class Update(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)

    def run(self):
        pass        #something you want to run in the background

continous = Update
continous.daemon = True
continous.start()

同样有效吗?

1 个答案:

答案 0 :(得分:0)

threading documentation:“当没有活着的非守护程序线程时,整个Python程序退出”。守护程序线程将在申请完成后终止。

为了在python中实现系统守护进程,你应该使用os.fork。看看example of simple daemon