2010-12-27 3 views
6

아래 코드는 Python Win32 서비스를 작성하는 코드입니다. 서비스를 컴파일 할 때 service.msc에 가서 수동으로 시작해야합니다.Python Win32 서비스가 automaticlly로 시작합니다

내가 serivce를 설치할 때 옵션이 있습니까? myservice.exe를 설치하면 자동으로 시작됩니다. 아래

는 내 코드의 스 니펫 있습니다 : 당신은 create 명령을 sc.exe을 사용할 수 있습니다

import win32serviceutil 
import win32service 
import win32event 

class SmallestPythonService(win32serviceutil.ServiceFramework): 
    _svc_name_ = "ser_name" 
    _svc_display_name_ = "ser_descryption" 
    #_svc_description_='ddd' 
    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) 

답변

1

.

sc create MyPyService binPath= "C:\myservice.exe" DisplayName= "Some Python Service" 

자세한 내용은 Microsoft KB251192입니다.

win32serviceutil 또한 사용할 수있는 기능이 InstallService()입니다.

2

나는 이것을 ActiveState recipe에서 살펴볼 것이다. 이것은 서비스를 자동 시작하는 방법을 보여주는 win32serviceutil에 대한 래퍼입니다.

6

을 사용하여 서비스를 설치하고 자동으로 시작되도록 설정하십시오.

+0

Nativ 솔루션은 최적의 솔루션입니다! – enthus1ast

0

@Maciejg 내 서비스가 py2exe에와 사례보기 자동 시작하려면 여기를, 나를 위해 솔루션을 작동하지 않습니다

myservice.exe -auto -install 
관련 문제