I have used this question to learn install my python script as a service with ActivePython. I am able to install my script and remove it, as I would expect, but my problem is that once I start the script running, I then lose the ability to stop it or remove it. It just runs permanently and I cannot get rid of it. The answer to the linked question mentions checking a flag to stop the script. Can someone explain how to do this?
Right now the script does very little. just prints lines to a file every few seconds. I want to get it working before I move on to more complicated things.
class AppServerSvc (win32serviceutil.ServiceFramework):
_svc_name_ = "PythonTest"
_svc_display_name_ = "Python Test"
_svc_description_ = "This is a test of installing Python services"
self.hWaitStop = win32event.CreateEvent(None,0,0,None)
if __name__ == '__main__':
Of course you can't stop it, you're stuck in an infinite loop. Replace:
if win32event.WaitForSingleObject(self.hWaitStop, 5000) == win32event.WAIT_OBJECT_0: break
Should do the trick.