Hi Tim,

> How did you start the service?? 
I run it with the following command line:
python MyService.py install
python MyService.py start

> How do you know this? How are you monitoring state?
When I go to Windows Services list its state is "Starting" instead of "Running" 
so I cannot do any actions on it (e.g Stop)

I managed to get the proper state "Running" by removing the following line from 
SvcDoRun function:
self.ReportServiceStatus(win32service.SERVICE_RUNNING)
since it's already called from parent function SvcRun from 
win32serviceutil.ServiceFramework that calls SvcDoRun.

But when typing "python MyService.py start", my Service gets stuck in "Running" 
state.
Here is the updated code, am I missing something to notify the service as 
stopped?


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):
        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)


_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32

Reply via email to