473,397 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Daemon terminates unexpected

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-----

Feb 6 '06 #1
1 1970
Incorporating Fredrik's fix (I learned something new reading
that), try using an endless loop even if there is an exception
like this:

def run(self):
while True:
try:
<start an SMTP-Server
asyncore.loop()
except:
e = sys.exc_value()
<write exception in log>
<kill the SMTP server off>
time.sleep(60) # wait, avoid spinning

so that even if there is an exception, it'll get up and go again.

Steve
Feb 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rob Hunter | last post by:
Hi all. I want to run a Python daemon that manages a "to-do" queue. I want it so that the daemon is always running, where its running consists of looking at the queue to see if it has any jobs,...
3
by: bmgx | last post by:
This is what I am trying to find out, instruction on how to create a simple daemon on unix systems(Linux), can't find any info on usual sources..
1
by: Bob Swerdlow | last post by:
I've created a Python daemon that starts a bunch of BitTorrent downloader process. Everything is working fine when I start the daemon by hand (logged on as root). I can quit the session and see...
7
by: Michael Ransburg | last post by:
Hi! I have implemented a daemon in C++. It runs all the time, between reboots. Is there a way for other C++ classes to get a reference to the instance of this daemon class in order to call its...
2
by: Steph L | last post by:
Hi, A given Milter program compiles ok on OpenBSD/FreeBSD/Linux but not on Solaris : it uses daemon(3) http://www.openbsd.org/cgi-bin/man.cgi?query=daemon&apropos=0&sektion...
3
by: paul | last post by:
I am writing a daemon process that reads data from the serial port / dev/ttyS0. I am using pyserial & the method for setting up a daemon described in "Chris' Python Page"...
6
by: Johny | last post by:
Is it possible to run a Python program as daemon? Thanks
3
by: Scottman | last post by:
I am writing a server daemon that forks a child for every incoming request. The child process terminates when the client closes the connection. My problem is that I am unsure how to prevent the...
13
dmjpro
by: dmjpro | last post by:
class MainClass{ public static void main(String a){ //do something } } When i run this class file then JVM is the process having one main thread. Thread ends and process ends. I went...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.