windows service problem

A

Austin

class HelloService(win32serviceutil.ServiceFramework):
_svc_name_ = "HelloService"
_svc_display_name_ = "Hello Service"
def __init__(self,args):
win32serviceutil.ServiceFramework.__init__(self,args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
self.check = 1

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

def SvcDoRun(self):
win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)
while True:
CheckPoint('SvcDoRun')
if self.check == 0:
break

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

-----------------------------------------------------------------------

I modified the demo code from Python Programming on Win32.
CheckPoint is a class to open a file and write some words.
But the problem is that no matter how I re-start the service and the
CheckPoint() doesn't work.
Anything wrong?
 
K

Konstantin Veretennicov

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

Change last two lines to

self.check = 1
self.hWaitStop = win32event.CreateEvent(None, 0, 1, None)

(SvcDoRun is waiting for hWaitStop event, but you never signal it.)

- kv
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,737
Latest member
Georgeengab

Latest Threads

Top