AKM
AKM

Reputation: 6575

Python win32 service

I have a minimal python win32 service service.py that does nothing special:

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 service.py file with py2exe to service.exe and 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 resolve this problem?

Also here the distutil code:

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,
    },
 )

Upvotes: 3

Views: 7635

Answers (4)

mjsrs
mjsrs

Reputation: 21

try this setup:

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)

Upvotes: 1

mpaf
mpaf

Reputation: 6807

You probably might be missing the right PATH for finding all the DLLs required by the service. Usually the service gets installed as a 'LocalSystem' service so you need to add the PATH to the System (and not to User).

Try adding c:\python27 (or whatever the path to your python dlls is) to the SYSTEM PATH, restart the computer and check if it now starts fine.

Upvotes: 0

Anders
Anders

Reputation: 6218

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

Upvotes: 6

Daren Thomas
Daren Thomas

Reputation: 70354

A quick google came up with this: http://islascruz.org/html/index.php?gadget=StaticPage&action=Page&id=6

It has Italian comments, but I can help you translate some stuff if you don't know Italian.

To truly debug your problem, I guess we will need to see your setup.py distutils script...

Upvotes: 0

Related Questions