I'm trying to start a simple service example:
someservice.py:
import win32serviceutil
import win32service
import win32event
class SmallestPythonService(win32serviceutil.ServiceFramework):
_svc_name_ = "SmallestPythonService"
_svc_display_name_ = "display service"
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
python someservice.py install
everything is fine and the service appears in the Windows service list, but
python someservice.py start
fails with "Error 1053: The service did not respond to the start or control request in a timely fashion", but there is not any delay.
I googled a solution, which said it happens when pythonservice.exe
can't locate python27.dll
. It actually couldn't so I added C:\Python27
to PATH
. Now pythonservice.exe
runs fine, but Error 1053 still there.
I'm running Python 2.7.2 with pywin32 216 on Windows 7 Ultimate with admin privilegies.
pythonservice.exe
can't locatepython27.dll
. Took me forever to figure this out! Thanks :) – Gili