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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQBD5xp7/gltz1ptagYRAmzSAJ4piq2RvFQaU9uftcHBO+qYeRXzIgCghNV j
UuCIwcujvs/IdrG9n4ma9pE=
=XO1b
-----END PGP SIGNATURE-----