Python Windows服务 - 不干净地停止而不执行cmd

时间:2015-08-20 20:21:58

标签: python windows service windows-services

我正在编写我的第一个Windows服务,在python中有一些问题。在问题出现之前,我只包括部分代码

Logon_Service.py

class EditService (win32serviceutil.ServiceFramework):
    _svc_name_ = "Edit Login Service"
    _svc_display_name_ = "Edit Login Service"

    def __init__(self,args):
        win32serviceutil.ServiceFramework.__init__(self,args)
        self.stop_event = win32event.CreateEvent(None,0,0,None)
        socket.setdefaulttimeout(60)
        self.stop_requested = False

    def SvcStop(self):
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        win32event.SetEvent(self.stop_event)
        logging.info('Stopping service ...')
        self.stop_requested = True

    def SvcDoRun(self):
        servicemanager.LogMsg(
            servicemanager.EVENTLOG_INFORMATION_TYPE,
            servicemanager.PYS_SERVICE_STARTED,
            (self._svc_name_,'')
        )
        self.main()

    def main(self):
        while 1:
            if self.stop_requested:
                logging.info('A stop signal was received, breaking loop')
                break

            repo = AvidRepo(r"C:\Users\Administrator\Desktop\WorkGroups",r"C:\LogonTemp")
            repo.downloadSettings()
            repo.validateSettings()


            db = r"C:\Users\Administrator\Desktop\WorkGroups\test.db"

            key = repo.workgroupRegKey

            listofvalues = read_registry(key)
            currentWorkgroup = [f for f in listofvalues if f.startswith(r"/Avid/Workgroup-")]

            #if list index out of range

            groupNumber = currentWorkgroup[0][-2:]

            #Update Current Workgroup File
            currentWorkgroupFile = os.path.join(os.path.join(repo.repoDestination,"WG"+groupNumber),r"Workgroup\AvidWorkgroup.txt")
            shutil.move(currentWorkgroupFile,repo.workgroupFile)

            #Update Current BGInfo File
            currentBGInfo = os.path.join(os.path.join(repo.repoDestination,"WG"+groupNumber),r"BGINFO\x64Client.bgi")
            shutil.move(currentBGInfo,repo.bgLocation)
            time.sleep(5)
            #Execute New BGInfo File

            dir= ""
            cmd = r"cmd C:\BGInfo\Bginfo.exe /ic:\BGinfo\x64Client.bgi /timer:0 /silent /NOLICPROMPT"


            ret = call(cmd)

服务不会干净地停止 - 而且subprocess.call()命令也不起作用。停止服务时,它会一直尝试直到超时。 subprocess.call从服务外部工作,但不在服务中工作。

任何想法?

0 个答案:

没有答案