zoukankan      html  css  js  c++  java
  • 将python的程序包装成windows下的service

      使用python编写的脚本应用程序,在运行的时候需要有python的运行环境,但是我们肯定是希望整个python程序能够像应用程序一样打包生成一个包括其运行环境的exe文件包,这是第一步,但是要想使用net start这样的方式启动, 还需要将该exe注册到服务里面去,使用exe install完成。

     

    #SmallestService.py  
    #AsampledemonstratingthesmallestpossibleservicewritteninPython.  
     
    importwin32serviceutil  
    importwin32service  
    importwin32event  
     
    classSmallestPythonService(win32serviceutil.ServiceFramework):  
        _svc_name_="SmallestPythonService" 
        _svc_display_name_="ThesmallestpossiblePythonService" 
        def__init__(self,args):  
            win32serviceutil.ServiceFramework.__init__(self,args)  
            #Createaneventwhichwewillusetowaiton.  
            #The"servicestop"requestwillsetthisevent.  
            self.hWaitStop=win32event.CreateEvent(None,0,0,None)  
     
      defSvcStop(self):  
         #Beforewedoanything,telltheSCMwearestartingthestopprocess.  
            self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)  
            #Andsetmyevent.  
            win32event.SetEvent(self.hWaitStop)
    
        defSvcDoRun(self):
            #把你的程序代码放到这里就OK了
            win32event.WaitForSingleObject(self.hWaitStop,win32event.INFINITE)
    
    if__name__=='__main__':
        win32serviceutil.HandleCommandLine(SmallestPythonService)
    

      

  • 相关阅读:
    POJ 2175 Evacuation Plan 费用流 负圈定理
    POJ 2983 Is the Information Reliable? 差分约束
    codeforces 420B Online Meeting
    POJ 3181 Dollar Dayz DP
    POJ Ant Counting DP
    POJ 1742 Coins DP 01背包
    中国儒学史
    产品思维30讲
    Java多线程编程核心技术
    编写高质量代码:改善Java程序的151个建议
  • 原文地址:https://www.cnblogs.com/luomingchuan/p/3776113.html
Copyright © 2011-2022 走看看