Reputation: 2087
Using python 2.7 on windows 7 64 bit machine. I had followed the link http://essiene.blogspot.in/2005/04/python-windows-services.html But getting error when seen in Events Viewer Windows Logs as Traceback (most recent call last): File "C:\Python27\lib\site-packages\win32\lib\win32serviceutil.py", line 835, in SvcRun self.SvcDoRun() AttributeError: Myservice instance has no attribute 'SvcDoRun'.
Code snippet is as:
import win32service
import win32serviceutil
import win32api
import win32con
class Myservice(win32serviceutil.ServiceFramework):
_svc_name_ = "Myservice"
_svc_display_name_ = "Myservice"
def __init__(self,args):
win32serviceutil.ServiceFramework.__init__(self,args)
self.isAlive = True
def SvcDoRun(self):
while self.isAlive:
if len(List)!=0:
for i in range(0,len(List)):
t = ThreadClass(NameList[i],name)
t.start()
def SvcStop(self):
import servicemanager
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
self.isAlive = False
def ctrlHandler(ctrlType):
return True
if __name__ == '__main__':
win32api.SetConsoleCtrlHandler(ctrlHandler, True)
win32serviceutil.HandleCommandLine(Myservice)
Upvotes: 0
Views: 774
Reputation: 11
I stumbled over the same problem. You need to indent the function definitions, otherwise they don't belong to the MyService class. So your code must look like this:
import win32service
import win32serviceutil
import win32api
import win32con
class Myservice(win32serviceutil.ServiceFramework):
_svc_name_ = "Myservice"
_svc_display_name_ = "Myservice"
def __init__(self,args):
win32serviceutil.ServiceFramework.__init__(self,args)
self.isAlive = True
def SvcDoRun(self):
while self.isAlive:
if len(List)!=0:
for i in range(0,len(List)):
t = ThreadClass(NameList[i],name)
t.start()
def SvcStop(self):
import servicemanager
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
self.isAlive = False
def ctrlHandler(ctrlType):
return True
if __name__ == '__main__':
win32api.SetConsoleCtrlHandler(ctrlHandler, True)
win32serviceutil.HandleCommandLine(Myservice)
Upvotes: 1