Question

I'm relatively new to python and I've only skimmed the surface of programming so far, which is why I'm confused about daemons. I generally know what they do, but I'm not sure what the best way to implement them is in python. I found this link which demonstrates how to create daemons in python. However, I was wondering if this

#!/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()

would be just as effective?

Was it helpful?

Solution

From threading documentation: "The entire Python program exits when no alive non-daemon threads are left". Daemon thread will just be terminated upon application finish.

In order to implement a system daemon in python you should use os.fork. Take a look at the example of simple daemon.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top