아래 코드는 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)
Nativ 솔루션은 최적의 솔루션입니다! – enthus1ast