Hi, I managed to install a Python script as a service using this recipe at ActiveState: win-services-helper
.
In order to get much use out of it, I included the business end of my program by replacing lines 99 - 100:
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')
My problem is, the service logs only one entry and then stops by itself. Then I go to services.msc
, attempt to start the service again, then Windows displays this message:
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.
How come my service thinks it has nothing to do when I placed it in an infinite loop? 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.
NOTE: My logging script uses simple file read/write to csv
. It doesn't use any fancy logging modules.