[python-win32] Service stucks in Starting state
k3ops at free.fr
k3ops at free.fr
Tue Apr 10 06:55:20 EDT 2018
Hi all,
I am new to 'pywin32' but I was able to create very quickly a new Windows service for my purpose thanks to your work!
Unfortunatelly when I install and then start my service, it gets stucked in Starting state and then I have no chance to stop or remove it except by restarting the computer.
Here is the code I used, could you help me on this one?
I added this line self.ReportServiceStatus(win32service.SERVICE_RUNNING) in SvcDoRun function compared to your example but it did not change anything.
Thanks
#!/usr/bin/env python3
import win32service
import win32serviceutil
import win32event
import servicemanager
class MyClass(win32serviceutil.ServiceFramework):
# you can NET START/STOP the service by the following name
_svc_name_ = "My_CLASS"
# this text shows up as the service name in the Service
# Control Manager (SCM)
_svc_display_name_ = "MY_CLASS"
# this text shows up as the description in the SCM
_svc_description_ = "MY_DESC"
def __init__(self, args):
# create Windows Service
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) # create an event to listen for stop requests on
def SvcDoRun(self):
self.ReportServiceStatus(win32service.SERVICE_RUNNING)
win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)
def SvcStop(self):
# tell the SCM we're shutting down
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
# fire the stop event
win32event.SetEvent(self.hWaitStop)
if __name__ == '__main__':
win32serviceutil.HandleCommandLine(MyClass)
More information about the python-win32
mailing list