Service not stopping

belen at netcom.no belen at netcom.no
Mon Oct 22 05:53:13 EDT 2001


Hello, 
I have written a small service in python. This sevice will essentially 
be a scheduled activity to zip and copy some directories.

This activity is created as a process to be able to retieve later on 
its handle to terminate the process. But it seems that as soon as the 
process is created it takes over and doesn't allow my service to get 
any messages from  the SCM.

This a copy of my service... Can someone tell me wheta I have been 
doing wrong? It would be of great help. Thanks a lot!!!

Belen

import win32serviceutil
import win32service
import win32event
import win32process
import os, sys
import win32api, win32pdhutil, win32con, sys

class ExtDocBackupService(win32serviceutil.ServiceFramework):
        _svc_name_="ExtDocBackupService"
        _svc_display_name_="External Documents Backup"
                               
        def __init__(self,args):
                win32serviceutil.ServiceFramework.__init__(self,args)
                 self.hWaitStop=win32event.CreateEvent(None,0,0,None)
         def SvcDoRun(self):
                self.Start_Scheduler()
                
                import servicemanager
                
                servicemanager.LogMsg(
                        servicemanager.EVENTLOG_INFORMATION_TYPE,
                        servicemanager.PYS_SERVICE_STARTED,
                        (self._svc_name_,''))

                while 1:                
                    win32event.WaitForMultipleObjects
((self.hWaitStop,self.hSched),0,win32event.INFINITE)
                self.ReportServiceStatus
(win32service.SERVICE_STOP_PENDING) 


         def SvcStop(self):
                import servicemanager
                
                servicemanager.LogMsg(
                        servicemanager.EVENTLOG_INFORMATION_TYPE,
                        servicemanager.PYS_SERVICE_STARTED,
                        (self._svc_name_,''))
                
                 try:
                        
                        self.Stop_Scheduler()
                        
                 except:
                        pass
                self.ReportServiceStatus
(win32service.SERVICE_STOP_PENDING) 
                 win32event.SetEvent(self.hWaitStop)
                 

         
         def Start_Scheduler(self):
                si=win32process.STARTUPINFO()
                result=win32process.CreateProcess(
                            None,
                            'python Schedule.py',
                            None,
                            None,
                            0,
                            0,
                            None,
                            None,
                                           si)
                
                     self.hSched=result[0]
                     
             
                        
        
        def Stop_Scheduler(self):
                        
                        
                        win32process.TerminateProcess(self.hSched, 0)
                        
                
         

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



 
 






More information about the Python-list mailing list