title: Python Daemons - Program Structure and Exception Control
body: <p>I've been doing amateur coding in Python for a while now and feel quite comfortable with it. Recently though I've been writing my first Daemon and am trying to come to terms with how my programs should flow.</p>
  
  <p>With my past programs, exceptions could be handled by simply aborting the program, perhaps after some minor cleaning up.  The only consideration I had to give to program structure was the effective handling of non-exception input. In effect, "Garbage In, Nothing Out".</p>
  
  <p>In my Daemon, there is an outside loop that effectively never ends and a sleep statement within it to control the interval at which things happen.  Processing of valid input data is easy but I'm struggling to understand the best practice for dealing with exceptions.  Sometimes the exception may occur within several levels of nested functions and each needs to return something to its parent, which must, in turn, return something to its parent until control returns to the outer-most loop.  Each function must be capable of handling any exception condition, not only for itself but also for all its subordinates.</p>
  
  <p>I apologise for the vagueness of my question but I'm wondering if anyone could offer me some general pointers into how these exceptions should be handled. Should I be looking at spawning sub-processes that can be terminated without impact to the parent? A (remote) possibility is that I'm doing things correctly and actually do need all that nested handling. Another very real possibility is that I haven't got a clue what I'm talking about. :)</p>
  
  <p>Steve</p>