Windows Service wasn't able to stop
yang-shuaijun opened this issue · comments
Picoman Yang commented
-
Expected behavior and actual behavior.
The service should be able to start and stop. -
Steps to reproduce the problem.
-
Version of Python and pywin32
Python: 3.11.6
OS: Windows Server 2022
pywin32: 306
The program is the following:
"""
Log masking main program entry point.
usage:
python main.py -c {config.json}
"""
import sys
import servicemanager
import win32service
import win32serviceutil
from log_watch import LogObserver
class LogMaskSvc(win32serviceutil.ServiceFramework):
_svc_name_ = "BBA Log mask"
_svc_display_name_ = "BBA Log mask"
_svc_description_ = "Mask GPS data in DLT or ASC files"
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.ssh = None
self.__log_observer = None
def SvcDoRun(self):
self.ReportServiceStatus(win32service.SERVICE_START_PENDING, waitHint=3000)
self.__log_observer = LogObserver(config='D:\log_mask\config.json')
self.ReportServiceStatus(win32service.SERVICE_RUNNING, waitHint=3000)
self.__log_observer.run()
def SvcStop(self, control):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING, waitHint=3000)
self.__log_observer.stop()
self.ReportServiceStatus(win32service.SERVICE_STOPPED, waitHint=3000)
if __name__ == '__main__':
win32serviceutil.HandleCommandLine(LogMaskSvc)
The Service status is:
SERVICE_NAME: BBA Log mask
DISPLAY_NAME: BBA Log mask
TYPE : 10 WIN32_OWN_PROCESS
STATE : 2 START_PENDING
(NOT_STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x1388
Mark Hammond commented
There's probably an exception being thrown somewhere in your service. See https://github.com/mhammond/pywin32#support for one way of getting help using pywin32.