Python win32 service

I have a minimal win32 win32 service service.pythat does nothing:

import win32serviceutil
import win32service
import win32event

class SmallestPythonService(win32serviceutil.ServiceFramework):
    _svc_name_ = "SmallestPythonService"
    _svc_display_name_ = "display service"
    # _svc_description_='ddd'

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

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

    def SvcDoRun(self):     
         win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)

if __name__=='__main__':
    win32serviceutil.HandleCommandLine(SmallestPythonService)

When I run:

 service.py install
 service.py start 

It works fine, but when I compile the file service.pyfrom py2exeto service.exeand run the following:

service.exe install
service.exe start [or trying to restart the service  from the Services.msc]

I get this message:

Could not start the  service name service on Local Computer.
Error 1053: The service did not respond to the start or control request in a timely fashion

How can I solve this problem?

Also here is the code distutil:

from distutils.core import setup
import py2exe

py2exe_options = {"includes": ['decimal'],'bundle_files': 1}

setup(console=[{"script":'Service.py'}], 
    options={"py2exe": py2exe_options}, 
    zipfile = None,
    },
 )
+3
source share
4 answers

Replace: setup(console=[{"script":'Service.py'}]with setup(service=[{"script":'Service.py'}]. Instead of using the console, use.

+6
source

try this setting:

py2exe_options = {"includes": ['decimal'],'bundle_files': 1}
setup(
    service=[{'modules':'Service.py','cmdline_style':'pywin32','description':'your service description'}],
    options={'py2exe':py2exe_options},
    zipfile=None)
+1
source
0

, PATH DLL, . "LocalSystem", PATH ( ).

c:\python27 ( DLL python) SYSTEM PATH, , .

0

Source: https://habr.com/ru/post/1781446/


All Articles