如何将用python编写的Windows服务转换为exe

时间:2018-09-23 17:07:02

标签: windows python-3.x service

此代码必须在python python test.py install和python test.py start中运行 我用pyinstaller转换为exe不起作用... 我想为客户提供一个文件。 如何在不使用python test.py install的情况下以exe格式运行???

class AppServerSvc (win32serviceutil.ServiceFramework):
_svc_name_ = "my_service_name"
_svc_display_name_ = "my service"

def __init__(self,args):
    win32serviceutil.ServiceFramework.__init__(self,args)
    SetConsoleCtrlHandler(lambda x: True, True)
    self.hWaitStop = win32event.CreateEvent(None,0,0,None)

def SvcStop(self):
    self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
    win32event.SetEvent(self.hWaitStop)
    self.run = False

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

def main(self):
    while self.run == True
        try :
            <your code>
        except :
            time.sleep(3)
            <may be an error log here>

如果名称 =='主要”:     win32serviceutil.HandleCommandLine(AppServerSvc)

0 个答案:

没有答案