473,545 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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__=="__ma in__":
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/gltz1ptagYRAmzS AJ4piq2RvFQaU9u ftcHBO+qYeRXzIg CghNVj
UuCIwcujvs/IdrG9n4ma9pE=
=XO1b
-----END PGP SIGNATURE-----

Feb 6 '06 #1
1 1975
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
5641
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, and if it does, remove the job from the queue and "do the job". This all seems quite doable using the synchronized Queue.py module and this page...
3
2503
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
2133
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 that the daemon is running and the subprocesses are running, too. However, when I configure the system to automatically start the daemon on boot-up,...
7
4229
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 methods directly? E.G.: 1) System Start - daemon class is instantiated and launched
2
3808
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 =0&manpath=OpenBSD+Current&arch=i386&format=html http://www.freebsd.org/cgi/man.cgi?query=daemon&sektion=3&apropos=0 &manpath=FreeBSD+5.1-RELEASE
3
4274
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" (http://homepage.hispeed.ch/py430/ python/) on an Ubuntu linux pc. Everything works great EXCEPT... in the daemon script, there are two lines to change the uid & gid...
6
3982
by: Johny | last post by:
Is it possible to run a Python program as daemon? Thanks
3
5190
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 child process from becoming defunct. Here is an over-simplified main function... int main(void) { // Daemonize int pid;
13
9253
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 through a link there i read about daemon thread.
0
7486
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7932
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7442
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6001
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4965
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3456
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
729
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.