Daemon terminates unexpected

Stefan Neumann stefan.neumann at freiheit.com
Mon Feb 6 04:58:34 EST 2006


I have written a daemon which should run endlessly. The structure looks
like this:

- start-stop-daemon forks my python program

then:

if __name__=="__main__":
    try:
        main()
    except Exception,e
        <write exception>

def main():
    # I need a starter to use the program also from the unittests
    starter=starter()
    starter.start()

    while True:
        #TODO: Catch kill signal
        # I know, dirty....
        sleep(10)

class Starter(Thread):

    def __init__(<not interesting>):
        Thread.__init__(self)
	<do some init stuff>
        self.setDaemon(True)

    def run(self):
        try:
            <start an SMTP-Server
            asyncore.loop()
        except Exception,e:
            <write exception in log>

The problem is now that the SMTP-Server quits donig its work. First I
thought, there will be an exception be thrown but actually, after
catching all global exceptions there is no log entry for it.

I really don't know why my program terminates. It happens nearly
regularly after five days.

Why I think, everything works correctly (correct me, if I am wrong):

Main will actually live forever because of the endless loop.
It starts a thread, which is set as daemon. This daemon will live until
all non daemon threads have terminated. So why does this program end?

I have read somethong about double-fork, can someone explain, why to use
this way for starting a daemon?

Thanks in advanced.

Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20060206/1e0d0671/attachment.sig>


More information about the Python-list mailing list