Python script service generates alert in the event log with id 7039

Viewed 100

If I try to do this it doesn't generate the warning:

Test.py install
Test.py start

Otherwise if I use pyinstaller:

pyinstaller -F --hidden-import=win32timezone Test.py

And then I try to do:

Test.exe install
Test.exe start

I see this warning in the event log:

A service process other than the one started by Service Control Manager connected when the TestService service started. Service Control Manager started process 5328 and connected process 1512.

Note that if the service is configured to start inside a debugger, this behavior is expected.

Script:

import servicemanager
import socket
import sys
import win32event
import win32service
import win32serviceutil


class TestService(win32serviceutil.ServiceFramework):
    _svc_name_ = "TestService"
    _svc_display_name_ = "Test Service"
    _svc_description_ = "My service description"

    def __init__(self, args):
        win32serviceutil.ServiceFramework.__init__(self, args)
        self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
        socket.setdefaulttimeout(60)

    def SvcStop(self):
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        win32event.SetEvent(self.hWaitStop)

    def SvcDoRun(self):
        rc = None
        while rc != win32event.WAIT_OBJECT_0:
            with open('C:\\TestService.log', 'a') as f:
                f.write('test service running...\n')
            rc = win32event.WaitForSingleObject(self.hWaitStop, 5000)


if __name__ == '__main__':
    if len(sys.argv) == 1:
        servicemanager.Initialize()
        servicemanager.PrepareToHostSingle(TestService)
        servicemanager.StartServiceCtrlDispatcher()
    else:
        win32serviceutil.HandleCommandLine(TestService)

How can I start the service without this warning appearing?

1 Answers

This is only a warning of windows complaining that the service fired two process. This is the normal behaviour of pyinstaller executables. You should ignore this kind of warning.
See the docs

Related