I am using the win32serviceutil.ServiceFramework class to write a Windows Service.
I have a use-case where I would like my service to terminate in such a way that the recovery actions (e.g. restart service) are triggered.
By default these recovery actions are triggered when the service terminates without reporting a status of SERVICE_STOPPED.
I have tried overriding svcRun and raising an exception or calling sys.exit(), eg
def SvcRun(self):
self.ReportServiceStatus(win32service.SERVICE_RUNNING)
# ideally this would cause the service process to end without any further calls to SetServiceStatus(),
# so the recovery actions are triggered.
raise Exception()
but pywin32 sets the service status to SERVICE_STOPPED in its cleanup actions after calling SvcRun.
https://github.com/mhammond/pywin32/blob/master/win32/src/PythonService.cpp#L907
Ideally there would be some way for SvcRun to flag that this cleanup should not be done.
My current workaround is to call os.kill(os.getpid(), signal.SIGABRT), which avoids the cleanup. But I would like to avoid such a nuclear option.
I am using the
win32serviceutil.ServiceFrameworkclass to write a Windows Service.I have a use-case where I would like my service to terminate in such a way that the recovery actions (e.g. restart service) are triggered.
By default these recovery actions are triggered when the service terminates without reporting a status of
SERVICE_STOPPED.I have tried overriding
svcRunand raising an exception or callingsys.exit(), egbut pywin32 sets the service status to
SERVICE_STOPPEDin its cleanup actions after callingSvcRun.https://github.com/mhammond/pywin32/blob/master/win32/src/PythonService.cpp#L907
Ideally there would be some way for
SvcRunto flag that this cleanup should not be done.My current workaround is to call
os.kill(os.getpid(), signal.SIGABRT), which avoids the cleanup. But I would like to avoid such a nuclear option.