title: Why does this Python service stop by itself in spite of an infinite loop?
body: <p>I managed to install a Python script as a service using <a href="http://code.activestate.com/recipes/551780-win-services-helper/" rel="nofollow">this recipe at ActiveState: <code>win-services-helper</code></a>.</p>
  
  <p>In order to get much use out of it, I included the business end of my program by replacing lines 99 - 100:</p>
  
  <pre><code> 95   class Test(Service):
   96       def start(self):
   97           self.runflag=True
   98           while self.runflag:
   99               # My logging script
  100               # goes here
  101        def stop(self):
  102            self.runflag=False
  103            self.log("I'm done")
  105
  106    instart(Test, 'aTest', 'Python Service Test')
  </code></pre>
  
  <p>My problem is, the service logs only one entry and then stops by itself. Then I go to <code>services.msc</code>, attempt to start the service again, then Windows displays this message:</p>
  
  <blockquote>
    <p>The Python Service Test service on Local Computer started and then stopped. Some services stop automatically when they have no work to do, for example, the Performance Logs and Alerts service.</p>
  </blockquote>
  
  <p><strong>How come my service thinks it has nothing to do when I placed it in an infinite loop?</strong> It should stop only when I shut down the computer and start working again the next time the computer is turned on, even without anyone logging in.</p>
  
  <p><strong>NOTE:</strong> My logging script uses simple file read/write to <code>csv</code>. It doesn't use any fancy logging modules.</p>